为什么nginx需要重启?

Ubuntu 16.04在启动时启动nginx。 它被configuration为在本地主机上代理多个开发网站。 当nginx第一次启动时,这些站点没有运行。

如果我启动网站并浏览到https://dev.mysite.com (在etc / hosts中configuration),浏览器会说连接被拒绝。 然后我重新启动nginx并连接。 为什么第一次拒绝?

 ☀ ps aux | grep nginx root 1805 0.0 0.0 129336 2348 ? Ss Sep22 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ... other processes ☔ sudo /usr/sbin/nginx -T nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful # configuration file /etc/nginx/nginx.conf: user www-data; worker_processes auto; pid /run/nginx.pid; ... details server { listen 80; return 307 https://$http_host$request_uri; } # Map hosts -> meteor apps. map $http_host $backend { site1-dev.site.io http://127.0.0.1:3006; site2-dev.site.io http://127.0.0.1:3000; site3-dev.site.io http://127.0.0.1:3010; site4-dev.site.io http://127.0.0.1:3012; site5-dev.site.io http://127.0.0.1:3014; } # Proxy web-socket connections map $http_upgrade $connection_upgrade { default upgrade; '' close; } # Serve HTTPS content server { listen 443 ssl http2; server_name *.site.io; # this domain must match Common Name (CN) in the SSL certificate ssl_certificate /etc/ssl/site.crt; ssl_certificate_key /etc/ssl/site.key; # performance enhancement for SSL ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; # safety enhancement to SSL: make sure we actually use a safe cipher ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # don't use SSLv3 ref: POODLE # Forward secrecy ssl_dhparam /etc/ssl/dhparam.pem; add_header Strict-Transport-Security "max-age=31536000;"; # pass all requests to Node location / { proxy_pass $backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; # allow websockets proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP add_header Cache-Control no-cache; } } 

容易,但我的浏览器将不会连接到他们,除非我重新启动nginx:

 ☀ sudo service nginx start ☔ sudo /usr/sbin/nginx -T ... Same output, but now browser can connect 

这是一个大问题吗? 不,这只是额外的一步,我不明白为什么。 我可以杀死/重新启动网站,并且在第一次之后从不需要重新启动nginx。

为什么nginx启动,然后需要重新启动?

更新:

所以,电脑启动,login,然后上class: ☔ sudo netstat -tulpen|grep nginx (no output) ☔ ps aux | grep nginx root 1843 0.0 0.0 129336 2320 ? Ss 08:53 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; (workers follow) ☔ sudo /usr/sbin/nginx -T
(no output)
☔ sudo netstat -tulpen|grep nginx (no output) ☔ ps aux | grep nginx root 1843 0.0 0.0 129336 2320 ? Ss 08:53 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; (workers follow) ☔ sudo /usr/sbin/nginx -T
(no output)

然后重新启动sudo service nginx restart☀ sudo netstat -tulpen|grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 167492 15135/nginx -g daem tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 0 167493 15135/nginx -g daem

我看着这个 ,但没有看到日志中的“绑定”错误。