ubuntu Nginx是活跃的,但服务只是间歇性的,没有错误

ct2axkht  于 2024-01-06  发布在  Nginx
关注(0)|答案(1)|浏览(193)

我试图提供一个简单的html页面与django,gunicorn和nginx.有一些错误,因为很多时候我的域名是显示域提供商的广告,而不是我的页面.它的工作时间很短之前,它似乎停止工作本身.当我写这篇文章,我在我的服务器上没有改变任何东西,它开始为我的页面服务,然后立即再次停止。我正在访问的域与浏览器缓存禁用和私人窗口。有时,www服务器会正确显示,而非www不会,反之亦然。
下面是我的nginx.conf:

  1. user www-data;
  2. worker_processes auto;
  3. pid /run/nginx.pid;
  4. error_log /var/log/nginx/error.log;
  5. include /etc/nginx/modules-enabled/*.conf;
  6. events {
  7. worker_connections 768;
  8. # multi_accept on;
  9. }
  10. http {
  11. ##
  12. # Basic Settings
  13. ##
  14. sendfile on;
  15. tcp_nopush on;
  16. types_hash_max_size 2048;
  17. # server_tokens off;
  18. # server_names_hash_bucket_size 64;
  19. # server_name_in_redirect off;
  20. include /etc/nginx/mime.types;
  21. default_type application/octet-stream;
  22. ##
  23. # SSL Settings
  24. ##
  25. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
  26. ssl_prefer_server_ciphers on;
  27. ##
  28. # Logging Settings
  29. ##
  30. access_log /var/log/nginx/access.log;
  31. ##
  32. # Gzip Settings
  33. ##
  34. gzip on;
  35. # gzip_vary on;
  36. # gzip_proxied any;
  37. # gzip_comp_level 6;
  38. # gzip_buffers 16 8k;
  39. # gzip_http_version 1.1;
  40. # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
  41. ##
  42. # Virtual Host Configs
  43. ##
  44. include /etc/nginx/conf.d/*.conf;
  45. include /etc/nginx/sites-enabled/*;
  46. }
  47. #mail {
  48. # # See sample authentication script at:
  49. # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
  50. #
  51. # # auth_http localhost/auth.php;
  52. # # pop3_capabilities "TOP" "USER";
  53. # # imap_capabilities "IMAP4rev1" "UIDPLUS";
  54. #
  55. # server {
  56. # listen localhost:110;
  57. # protocol pop3;
  58. # proxy on;
  59. # }
  60. #
  61. # server {
  62. # listen localhost:143;
  63. # protocol imap;
  64. # proxy on;
  65. # }
  66. #}

字符串
这里是我的网站-可用:

  1. server {
  2. listen 80;
  3. listen [::]:80;
  4. server_name www.example.com example.com;
  5. return 301 https://example.com$request_uri;
  6. }
  7. server {
  8. listen 443 ssl;
  9. listen [::]:443 ssl;
  10. server_name example.com;
  11. ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  12. ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  13. location = /favicon.ico { access_log off; log_not_found off; }
  14. location /static/ {
  15. root /root/example/project/staticfiles;
  16. }
  17. location / {
  18. include proxy_params;
  19. proxy_pass http://unix:/var/sockets/gunicorn.sock;
  20. }
  21. }


sudo cat /var/log/nginx/error.log不返回错误。
sudo nginx -t显示配置文件正常,测试成功。
我已经在systemctl中启用了nginx。systemctl status nginx返回

  1. Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
  2. Active: active (running) since Mon 2023-12-11 22:21:27 EST; 5min ago


gunicorn systemctl服务也在运行。
如果我将sites-available/example.com修改为

  1. server {
  2. server_name example.com www.example.com;
  3. return 200 "it works";
  4. }


然后systemctl restart nginx,什么都没变,我还在看域名提供商的广告页面。
cat /var/log/gunicorn/error.log返回正常日志,没有错误。使用systemctl重新启动gunicorn没有任何效果。
SSL_certs是使用certbot制作的。它们是正确的,因为页面在短时间内正常工作。
netstat -tulpen | grep 80显示监听80端口,端口443也是如此

  1. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 20990 718/nginx: master p
  2. tcp6 0 0 :::80 :::* LISTEN 0 20991 718/nginx: master p


lsof -i -n | fgrep nginx返回

  1. nginx 718 root 5u IPv4 20990 0t0 TCP *:http (LISTEN)
  2. nginx 718 root 6u IPv6 20991 0t0 TCP *:http (LISTEN)
  3. nginx 718 root 7u IPv4 20992 0t0 TCP *:https (LISTEN)
  4. nginx 718 root 8u IPv6 20993 0t0 TCP *:https (LISTEN)
  5. nginx 720 www-data 5u IPv4 20990 0t0 TCP *:http (LISTEN)
  6. nginx 720 www-data 6u IPv6 20991 0t0 TCP *:http (LISTEN)
  7. nginx 720 www-data 7u IPv4 20992 0t0 TCP *:https (LISTEN)
  8. nginx 720 www-data 8u IPv6 20993 0t0 TCP *:https (LISTEN)
  9. nginx 720 www-data 13u IPv4 74558 0t0 TCP 138.197.26.3:http->65.154.226.169:7976 (ESTABLISHED)
  10. nginx 721 www-data 5u IPv4 20990 0t0 TCP *:http (LISTEN)
  11. nginx 721 www-data 6u IPv6 20991 0t0 TCP *:http (LISTEN)
  12. nginx 721 www-data 7u IPv4 20992 0t0 TCP *:https (LISTEN)
  13. nginx 721 www-data 8u IPv6 20993 0t0 TCP *:https (LISTEN)


curl -I https://example.com显示

  1. HTTP/1.1 200 OK
  2. Server: nginx/1.24.0 (Ubuntu)
  3. Date: Tue, 12 Dec 2023 03:45:06 GMT
  4. Content-Type: text/html; charset=utf-8
  5. Content-Length: 147
  6. Connection: keep-alive
  7. X-Frame-Options: DENY
  8. Strict-Transport-Security: max-age=3600; includeSubDomains; preload
  9. X-Content-Type-Options: nosniff
  10. Referrer-Policy: same-origin
  11. Cross-Origin-Opener-Policy: same-origin


curl -I http://www.example.com按预期显示重定向

  1. HTTP/1.1 301 Moved Permanently
  2. Server: nginx/1.24.0 (Ubuntu)
  3. Date: Tue, 12 Dec 2023 03:46:56 GMT
  4. Content-Type: text/html
  5. Content-Length: 178
  6. Connection: keep-alive
  7. Location: https://example.com/


ufw statusStatus: inactive
重新启动虚拟机什么也没做。这是一个数字海洋VPS。Ubuntu 23.10。请帮助我了解我可以检查或记录,以了解为什么nginx服务器似乎 Flink 。

tct7dpnv

tct7dpnv1#

由于nslookup显示了多个IP地址,所以无论是有意还是无意,您基本上都有DNS load balancing。这可能是配置错误。您需要与设置DNS记录的人交谈,因为只有他们才能修复它。
(我相信当你使用裸IP时,你的IP会响应一个未配置的nging页面的原因是,你的nginx配置了server_name example.com,所以用裸IP联系它不会触发你想要的server配置。你需要在server_name中列出你的IP来获得对IP URL的所需响应。参见server_name文档,特别是“其他名称”部分。

相关问题