【问题标题】:Nginx redirects to default pageNginx 重定向到默认页面
【发布时间】:2017-07-18 07:10:06
【问题描述】:

我正在为我的 Django/Gunicorn/Nginx 服务器设置一个域。它适用于 IP 地址而不是 server_name 中的域名,但是当我添加域名时,它会重定向到默认的 Ubuntu Nginx 页面。我的 Nginx 文件如下所示(请注意,我用 example.com 替换了我的域):

路径:/etc/nginx/sites-available/projectname

server {
    listen 80;
    server_name example.com;
    return 301 $scheme://www.example.com$request_uri;
}

server {
    listen   80;
    server_name www.example.com;

    client_max_body_size 4G;

    location = /favicon.ico {access_log off; log_not_found off;}
    location /static/ {
    root /path/to/static/dir;
    }

    location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unix:/path/to/gunicorn.sock;
    }

}

我已经运行了命令 sudo nginx -t 和 sudo service nginx restart 但没有效果。如果我做错了什么,请告诉我。

【问题讨论】:

  • 你的配置中真的有server_name example.com;server_name www.example.com; 吗?
  • @fvu 不。我用 example.com 替换了我的域名,以便在此处发布。
  • 在这种情况下,明智的做法是将其添加到问题中,以避免错误的回答。
  • @fvu 你是对的,但由于某种原因我不能这样做。在这种情况下,域名重要吗?
  • 您在sites-available 中的文件是否与sites-enabled 符号链接?您可以通过nginx -T 看到nginx 看到的内容。

标签: django nginx


【解决方案1】:

1- 查看主要的 nginx.conf 如何包含所有配置文件。如果它包含启用站点的路径,则转到路径并查看站点下该站点的配置文件的快捷方式可用?

或者如果所有站点都在 nginx 配置文件中启用,包括直接可用

include /etc/nginx/sites-available/*;

2-混合两个服务器定义代码一次,并使用规则将非 www 转发到 www 3-如果不起作用,请检查 dns 配置问题,并通过 putty 从服务器内部查看结果,而不是使用浏览器从服务器外部查看结果,看看它是 nginx 问题还是 dns 配置问题。

注意:更改 dns 名称服务器需要几个小时才能对客户端产生影响。

【讨论】:

    猜你喜欢
    • 2012-08-02
    • 1970-01-01
    • 2018-02-04
    • 2014-09-03
    • 1970-01-01
    • 2012-09-11
    • 2013-12-26
    • 2021-11-14
    • 2018-03-04
    相关资源
    最近更新 更多