当我运行命令来测试我的配置时,我得到一个错误,说[…]:80有多个重复项.在此之前,我遇到了重复多个默认服务器的问题.
当我遇到多个默认服务器的问题时,我的文件看起来像这样
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/Nginx/html;
index index.PHP index.html index.htm;
server_name munki;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/Nginx/html;
}
location /report {
try_files $uri $uri/ =404;
}
location ~ \.PHP${
try_files $uri =404;
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
fastcgi_index index.PHP;
include fastcgi_params;
}
location /munki_repo/ {
alias /usr/local/munki_repo/;
autoindex off;
auth_basic "Restricted";
auth_basic_user_file /etc/Nginx/.htpasswd;
}
}
要解决该问题,我将配置更改为:
server {
listen 80;
listen [::]:80 ipv6only=on;
root /usr/share/Nginx/html;
index index.PHP index.html index.htm;
server_name munki;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/Nginx/html;
}
location /report {
try_files $uri $uri/ =404;
}
location ~ \.PHP${
try_files $uri =404;
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
fastcgi_index index.PHP;
include fastcgi_params;
}
location /munki_repo/ {
alias /usr/local/munki_repo/;
autoindex off;
auth_basic "Restricted";
auth_basic_user_file /etc/Nginx/.htpasswd;
}
}
更改后,我开始收到“[::]:80”重复选项错误.我不确定我做错了什么.这是我第一次使用Nginx.任何想法可能是什么问题?
我正在从我早先的评论中找到答案.
请发布错误消息(Nginx -t输出),因为它可能包含一些有用的见解.
你在运行什么Nginx版本?可能不再需要选项ipv6only = on,相反可能会产生问题.我在我的服务器块中有这个并且运行正常:
listen 80; listen [::]:80;
您是否有任何其他未发布的服务器块可能会相互冲突?
说明:让我们读一下当前(1.13)Nginx documentation:
ipv6only=on|off
this parameter (0.7.42) determines (via theIPV6_V6ONLYsocket option) whether an IPv6 socket listening on a wildcard address[::]
will accept only IPv6 connections or both IPv6 and IPv4 connections.
This parameter is turned on by default. It can only be set once on
start.
默认情况下,此参数处于启用状态,表示不应使用ipv6only = on.它没有任何好处,可能会产生问题(见下一点).
它只能设置一次就意味着如果你在配置中的任何地方不止一次(例如在不同的服务器块中),它将抛出一个错误:Nginx:[emerg]重复[::]的监听选项:80.