[英]Localhost on Docker Has "conflicting server name" Problem
I am trying to launch a docker image with localhost.我正在尝试使用本地主机启动 docker 映像。 The code is open sourced and here:代码是开源的,在这里:
https://github.com/Helium-MVC/Boilerplate https://github.com/Helium-MVC/Boilerplate
When I run docker-compose up
, I get the following:当我运行docker-compose up
,我得到以下信息:
helium_nginx | 2018/12/11 07:43:31 [warn] 1#1: conflicting server name "localhost" on 0.0.0.0:80, ignored
helium_nginx | nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
Now my docker site.conf only has 1 vhost:现在我的 docker site.conf 只有 1 个虚拟主机:
server {
#The port to listen on. SSL would listen on 443
listen 80 default_server;
#The name/alias the server listens for when deciding to use this configuration
server_name localhost _;
#Where the lo files are being written too
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
#Location of our site
location / {
#The root of the site is in public_html
root /code/site/public_html/;
index index.php index.html index.htm;
#important for pretty url and routing
try_files $uri $uri/ /index.php?rt=$uri&$args;
}
}
With it set in the yml like so:像这样在 yml 中设置它:
web:
image: nginx:latest
container_name: "helium_nginx"
ports:
- "8000:80"
volumes:
- ./:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
- ./nginx_custom_settings.conf:/etc/nginx/conf.d/nginx_custom_settings.conf
links: ['php']
What is weird is that is if I change the server_name
to something like www.example.com and place that name in my /etc/hosts
file, it works !奇怪的是,如果我将server_name
更改为 www.example.com 之类的名称并将该名称放在我的/etc/hosts
文件中,它就可以工作! Otherwise using localhost I get only the nginx default page .否则使用 localhost 我只能得到nginx 默认页面。 What can be wrong?有什么问题?
To provide an answer, I had to change the default nginx configuration.为了提供答案,我不得不更改默认的 nginx 配置。 In my YML I added:在我的 YML 中,我添加了:
services:
web:
image: nginx:latest
container_name: "helium_nginx"
ports:
- "8000:80"
volumes:
- ./:/usr/share/nginx/html
- ./:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
additionnx.conf:/etc/nginx/nginx.conf
The addittion was the -./nginx.conf:/etc/nginx/nginx.conf
添加的是-./nginx.conf:/etc/nginx/nginx.conf
The nginx.conf being copied was this:被复制的 nginx.conf 是这样的:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/site.conf;
}
What I changed was instead of having include /etc/nginx/conf.d/*.conf;
我改变的是 include /etc/nginx/conf.d/*.conf;
that would load all configuration, I loaded just the one I wanted, include /etc/nginx/conf.d/site.conf;
这将加载所有配置,我只加载了我想要的配置,包括/etc/nginx/conf.d/site.conf;
I'm using the nginx
image in docker, which has a default.conf
file with server_name localhost
and listening port 80. I simply replace that file and get this resolved.我在 docker 中使用nginx
图像,它有一个带有server_name localhost
和侦听端口 80 的default.conf
文件。我只需替换该文件并解决这个问题。
docker-compose.yml docker-compose.yml
version: '2'
services:
nginx:
image: nginx:latest
volumes:
- ./tmp/https_reverse_proxy.conf:/etc/nginx/conf.d/https_reverse_proxy.conf
- ./tmp/http_reverse_proxy.conf:/etc/nginx/conf.d/default.conf
ports:
- 80:80
- 443:443
and http_reverse_proxy.conf和 http_reverse_proxy.conf
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.