所以我遇到了一个问题,在其他方面相同的主机上看起来nginx的configuration看起来是完全相同的,但是它只是在一个而不是另外两个上运行。 本质上试图通过https连接导致连接被拒绝的服务器,但另一个工作正常。 这显然是在nginx级别发生的,因为请求甚至没有把它运行到nginx后面的进程,修复nginx conf就解决了这个问题。
nginx.conf:
user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## client_max_body_size 50M; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
启用网站的端口80configuration:
server { listen [::]:80; server_name [my_domain].com [hostname].[subdomain].com; location / { return 301 https://$server_name$request_uri; } }
启用站点的端口443configuration:
server { listen 443 default_server ssl; listen [::]:443 ssl; server_name [my_domain].com [hostname].[subdomain].com; ssl_certificate /etc/ssl/certs/nginx/[certname].pem; ssl_certificate_key /etc/ssl/certs/nginx/[certname]-key.pem; root /var/www/[document root]/; index index.html; location /api { proxy_pass http://127.0.0.1:[internal port]; } location /web { proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://127.0.0.1:[internal port]; } location / { try_files $uri $uri/ =404; } }
最初我listen [::]:443 ssl; 只在host1上运行,而在host2和host3上运行,添加default_server使host2和host3正常运行。 所有这三个主机都是通过saltstack进行configuration的,而且我只需要最less的交互就可以设置它们,但是我能够想到的主机之间的唯一区别是host1和host2与host3不同,它们显然不能成为问题。 我可能错过了什么,使这些主机不同,导致需要不同的configuration。
编辑:记得检查你的版本,我是一个白痴
总是有一个默认的服务器。 default_server选项只是让你select默认服务器而不是nginxselect它。 如果每个服务器上的文件名不同,它们的评估顺序可能会不同 – 这意味着nginx可能已经使用了不同的server块作为每个服务器上的默认server块。
请参阅此文档了解更多