0
我爲我的Django/Gunicorn/Nginx服務器設置了一個域。它可以正常使用IP地址而不是server_name中的域名,但是當我添加域名時,它將重定向到默認的Ubuntu Nginx頁面。我的Nginx的文件看起來像這樣(請注意,我代替我的example.com域):Nginx重定向到默認頁面
路徑:在/ etc/nginx的/網站可用/項目名稱
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服務nginx重啓但不起作用。請讓我知道如果我做錯了什麼。
你真的在你的配置中有'server_name example.com;'和'server_name www.example.com;'嗎? – fvu
@fvu號我用example.com替換了我的域名在這裏發佈。 –
在這種情況下,將這個問題添加到問題中是明智的做法,以避免錯誤的回覆。 – fvu