当域名中没有 www 时,Nginx 在没有 gunicorn 的情况下加载
Nginx loading without gunicorn when theres no www in the domain name
当我在搜索的域名中没有 www 的情况下查找我的域时,我收到 404 Not Found nginx/1.18.0 (Ubuntu) 错误。它找到了 nginx,所以它显然找到了我的服务器,但我找不到没有 www 就无法加载 gunicorn 的人。 My name servers 所有指向写入 ip 地址的地址都指向左侧带有我的域名的地址,这些地址是我将其留空或将 @ 放在该字段中的地方。我已经阅读了我用来确保完成每一步的指南,是否有一些配置我可能搞砸了?
我在 /var/log/nginx
中的错误日志没有显示任何相关信息,我在 /var/log/webapp
中的日志也没有显示任何相关内容,所以我不明白为什么没有 www[= 就不会加载 gunicorn 16=]
我发现这可能与我在 nginx 中的配置文件有关所以这是我的 /etc/nginx/sties-enabled/webapp
server {
server_name www.websitename.com;
location /static {
alias /home/sai/webapp/website/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.websitename.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.websitename.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.websitename.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name www.websitename.com;
return 404; # managed by Certbot
}
我发现我的错误可能是 certbot 仅将 www.websitename.com 重定向到 https,所以我将尝试找出如何向其添加 websitename.com 因为只需添加另一个 if under 使我的 nginx 无法重启
因此,如果您查看 here 他们在单独的服务器块中执行所有操作。我对他们的代码和我的代码之间的差异感到不舒服,而且我不完全理解差异的含义,因此任何评论或其他答案都会有所帮助,但这应该按照文件格式为您修复。加到最下面就可以了
server {
if ($host = websitename.com) {
return 301 https://$host$request_uri;
} #managed by Certbot
listen 80;
server_name websitename.com;
return 404;
}
然后将其设为您的 conf 运行 sudo certbot --nginx -d websitename.com -d www.websitename.com
它应该为您的域和工作创建 ssl 证书
server {
server_name websitename.com www.websitename.com;
location /static {
alias /home/sai/webapp/website/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.websitename.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.websitename.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}```
当我在搜索的域名中没有 www 的情况下查找我的域时,我收到 404 Not Found nginx/1.18.0 (Ubuntu) 错误。它找到了 nginx,所以它显然找到了我的服务器,但我找不到没有 www 就无法加载 gunicorn 的人。 My name servers 所有指向写入 ip 地址的地址都指向左侧带有我的域名的地址,这些地址是我将其留空或将 @ 放在该字段中的地方。我已经阅读了我用来确保完成每一步的指南,是否有一些配置我可能搞砸了?
我在 /var/log/nginx
中的错误日志没有显示任何相关信息,我在 /var/log/webapp
中的日志也没有显示任何相关内容,所以我不明白为什么没有 www[= 就不会加载 gunicorn 16=]
我发现这可能与我在 nginx 中的配置文件有关所以这是我的 /etc/nginx/sties-enabled/webapp
server {
server_name www.websitename.com;
location /static {
alias /home/sai/webapp/website/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.websitename.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.websitename.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.websitename.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name www.websitename.com;
return 404; # managed by Certbot
}
我发现我的错误可能是 certbot 仅将 www.websitename.com 重定向到 https,所以我将尝试找出如何向其添加 websitename.com 因为只需添加另一个 if under 使我的 nginx 无法重启
因此,如果您查看 here 他们在单独的服务器块中执行所有操作。我对他们的代码和我的代码之间的差异感到不舒服,而且我不完全理解差异的含义,因此任何评论或其他答案都会有所帮助,但这应该按照文件格式为您修复。加到最下面就可以了
server {
if ($host = websitename.com) {
return 301 https://$host$request_uri;
} #managed by Certbot
listen 80;
server_name websitename.com;
return 404;
}
然后将其设为您的 conf 运行 sudo certbot --nginx -d websitename.com -d www.websitename.com
它应该为您的域和工作创建 ssl 证书
server {
server_name websitename.com www.websitename.com;
location /static {
alias /home/sai/webapp/website/static;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.websitename.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.websitename.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}```