I try to create a small webserver on my raspberry pi with docker. This is my docker-compose file:
version: "3.6"
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- /home/pi/testData/code:/var/www/html
- /home/pi/testData/site.conf:/etc/nginx/conf.d/site.conf
depends_on:
- php
php:
image: php:7.4-fpm
volumes:
- /home/pi/testData/code:/var/www/html
And this my site.conf
server {
index index.html index.php;
listen 80;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Inside of the folder /home/pi/testData/code
is a file named index.php
which just echos a Hello World.
So this file will be mapped into the Docker Container into the path /var/www/html/
and inside of the site.conf
is the root mentioned also to /var/www/html
.
I also checked if the files are really available inside of the nginx container - both are.
So as I understand it: If I put an index-file inside of the /var/www/html
folder of my nginx docker container, then this file should be displayed if I call the IP of my Raspberry pi on Port 8080.
But unfortunately I only receive the Welcome to Nginx Page.
Did I miss something or did I something wrong?
CodePudding user response:
Nginx will load configuration files found in /etc/nginx/conf.d/
and their names ends with .conf
as suffix in alphabetical order.
Your configuration does have conflicting server name with the default configuration file of nginx. /etc/nginx/conf.d/default.conf
you can check that by exec into nginx container and run nginx -t
command to check the configuration for warnings and errors.
you should see something like:
[warn] 502#502: conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
you should rename the default file to a something like default.conf.old
or you can simply overwrite its contents with your configuration.