我试图提供一个简单的html页面与django,gunicorn和nginx.有一些错误,因为很多时候我的域名是显示域提供商的广告,而不是我的页面.它的工作时间很短之前,它似乎停止工作本身.当我写这篇文章,我在我的服务器上没有改变任何东西,它开始为我的页面服务,然后立即再次停止。我正在访问的域与浏览器缓存禁用和私人窗口。有时,www服务器会正确显示,而非www不会,反之亦然。
下面是我的nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
字符串
这里是我的网站-可用:
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /root/example/project/staticfiles;
}
location / {
include proxy_params;
proxy_pass http://unix:/var/sockets/gunicorn.sock;
}
}
型sudo cat /var/log/nginx/error.log
不返回错误。sudo nginx -t
显示配置文件正常,测试成功。
我已经在systemctl中启用了nginx。systemctl status nginx
返回
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Mon 2023-12-11 22:21:27 EST; 5min ago
型
gunicorn systemctl服务也在运行。
如果我将sites-available/example.com修改为
server {
server_name example.com www.example.com;
return 200 "it works";
}
型
然后systemctl restart nginx
,什么都没变,我还在看域名提供商的广告页面。cat /var/log/gunicorn/error.log
返回正常日志,没有错误。使用systemctl重新启动gunicorn没有任何效果。
SSL_certs是使用certbot制作的。它们是正确的,因为页面在短时间内正常工作。netstat -tulpen | grep 80
显示监听80端口,端口443也是如此
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 20990 718/nginx: master p
tcp6 0 0 :::80 :::* LISTEN 0 20991 718/nginx: master p
型lsof -i -n | fgrep nginx
返回
nginx 718 root 5u IPv4 20990 0t0 TCP *:http (LISTEN)
nginx 718 root 6u IPv6 20991 0t0 TCP *:http (LISTEN)
nginx 718 root 7u IPv4 20992 0t0 TCP *:https (LISTEN)
nginx 718 root 8u IPv6 20993 0t0 TCP *:https (LISTEN)
nginx 720 www-data 5u IPv4 20990 0t0 TCP *:http (LISTEN)
nginx 720 www-data 6u IPv6 20991 0t0 TCP *:http (LISTEN)
nginx 720 www-data 7u IPv4 20992 0t0 TCP *:https (LISTEN)
nginx 720 www-data 8u IPv6 20993 0t0 TCP *:https (LISTEN)
nginx 720 www-data 13u IPv4 74558 0t0 TCP 138.197.26.3:http->65.154.226.169:7976 (ESTABLISHED)
nginx 721 www-data 5u IPv4 20990 0t0 TCP *:http (LISTEN)
nginx 721 www-data 6u IPv6 20991 0t0 TCP *:http (LISTEN)
nginx 721 www-data 7u IPv4 20992 0t0 TCP *:https (LISTEN)
nginx 721 www-data 8u IPv6 20993 0t0 TCP *:https (LISTEN)
型curl -I https://example.com
显示
HTTP/1.1 200 OK
Server: nginx/1.24.0 (Ubuntu)
Date: Tue, 12 Dec 2023 03:45:06 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 147
Connection: keep-alive
X-Frame-Options: DENY
Strict-Transport-Security: max-age=3600; includeSubDomains; preload
X-Content-Type-Options: nosniff
Referrer-Policy: same-origin
Cross-Origin-Opener-Policy: same-origin
型curl -I http://www.example.com
按预期显示重定向
HTTP/1.1 301 Moved Permanently
Server: nginx/1.24.0 (Ubuntu)
Date: Tue, 12 Dec 2023 03:46:56 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://example.com/
型ufw status
是Status: inactive
重新启动虚拟机什么也没做。这是一个数字海洋VPS。Ubuntu 23.10。请帮助我了解我可以检查或记录,以了解为什么nginx服务器似乎 Flink 。
1条答案
按热度按时间tct7dpnv1#
由于
nslookup
显示了多个IP地址,所以无论是有意还是无意,您基本上都有DNS load balancing。这可能是配置错误。您需要与设置DNS记录的人交谈,因为只有他们才能修复它。(我相信当你使用裸IP时,你的IP会响应一个未配置的nging页面的原因是,你的nginx配置了
server_name example.com
,所以用裸IP联系它不会触发你想要的server
配置。你需要在server_name
中列出你的IP来获得对IP URL的所需响应。参见server_name
文档,特别是“其他名称”部分。