[英]Nginx default page on docker
// docker-compose.yml
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./code:/code
# - ./site/site.conf:/etc/nginx/conf.d/site.conf
- ./site/site.conf:/etc/nginx/sites-available/site.conf
- ./site/site.conf:/etc/nginx/sites-enabled/site.conf
links:
- php
php:
build: ./php
volumes:
- ./code:/code
// site/site.conf
server {
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;
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;
}
}
I have the above configuration for nginx running inside docker. 我在docker中运行的nginx具有以上配置。 For some reason it keeps on showing the default nginx page.
由于某些原因,它会继续显示默认的nginx页面。
Inside the container there is a file /etc/nginx/nginx.conf
which includes all the *.conf
from the conf.d
directory but still unable to get my conf worked. 容器内有一个文件
/etc/nginx/nginx.conf
,其中包含conf.d
目录中的所有*.conf
文件,但仍无法使我的conf工作。
Then i tried copying my files into sites-available and sites-enabled folders still no luck. 然后,我尝试将文件复制到站点可用文件夹和启用站点的文件夹中,但仍然没有运气。
Kindly help Thanks 请帮助谢谢
There are three things we need to do to get nginx up and running. 要启动和运行Nginx,我们需要做三件事。
The most efficient solution is to create a Dockerfile that solves all three of these nginx issues and put it in docker-compose.yml 's nginx service definition. 最有效的解决方案是创建一个Dockerfile可以解决所有这三个问题,nginx的,并把它放在搬运工,compose.yml的nginx的服务定义。 This config helps correct the nginx user and includes
sites-enabled/.conf
此配置有助于更正Nginx用户,并包括
sites-enabled/.conf
# /etc/nginx/nginx.conf: Changes user to www-data and includes /etc/nginx/sites-enabled/*.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*;
open_file_cache max=100;
}
daemon off;
Both the previous nginx.conf and this Dockerfile should be stored in the same directory. 之前的nginx.conf和此Dockerfile都应存储在同一目录中。
# <your-nginx-build-context>/Dockerfile
FROM nginx:latest
# The default nginx.conf DOES NOT include /etc/nginx/sites-enabled/*.conf
COPY nginx.conf /etc/nginx/
COPY symfony.conf /etc/nginx/sites-available/
# Solves 1
RUN mkdir -p /etc/nginx/sites-enabled/ \
&& ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/symfony.conf \
&& rm /etc/nginx/conf.d/default.conf
# Solves 2
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf
# Solves 3
RUN usermod -u 1000 www-data
CMD ["nginx"]
EXPOSE 80
EXPOSE 443
Make sure to update the nginx service definition in docker-compose.yml with something like: 确保使用类似以下内容更新docker-compose.yml中的nginx服务定义:
web:
build: ./nginx/Dockerfile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.