Redirect Nginx www.到非www.重定向不工作
我按照上的说明将www重定向到非www。我正在尝试重定向以下格式:Redirect Nginx www.到非www.重定向不工作,redirect,ssl,nginx,ssl-certificate,Redirect,Ssl,Nginx,Ssl Certificate,我按照上的说明将www重定向到非www。我正在尝试重定向以下格式: http://example.com http://www.example.com https://www.example.com 所有收件人: https://example.com http://example.com正在重定向到https。然而,另外两个,即www.,则不是。这是我的nginx.conf: upstream app_server { server 127.0.0.1:9000 fail_time
http://example.com
http://www.example.com
https://www.example.com
所有收件人:
https://example.com
http://example.com
正在重定向到https
。然而,另外两个,即www.
,则不是。这是我的nginx.conf:
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
#
# Redirect all www to non-www
#
server {
server_name www.example.com;
ssl_certificate /src/bin/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/ssl/private/STAR_example_com.key;
listen *:80;
listen *:443 ssl spdy;
listen [::]:80 ipv6only=on;
listen [::]:443 ssl spdy ipv6only=on;
return 301 https://example.com$request_uri;
}
#
# Redirect all non-encrypted to encrypted
#
server {
server_name example.com;
listen *:80;
listen [::]:80;
return 301 https://example.com$request_uri;
}
#
# There we go!
#
server {
server_name example.com;
ssl_certificate /src/bin/ssl/ssl-bundle.crt;
ssl_certificate_key /etc/ssl/private/STAR_example_com.key;
listen *:443 ssl spdy;
listen [::]:443 ssl spdy;
# rest goes here...
root /usr/share/nginx/html;
index base.html index.html index.htm;
client_max_body_size 4G;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /src/media;
expires 1y;
add_header Cache-Control "public";
}
# your Django project's static files - amend as required
location /static {
alias /src/static;
expires 1y;
add_header Cache-Control "public";
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
我在nginx日志文件中没有看到任何指示错误的内容。当我尝试访问
www.
版本时,是否有地方可以查找错误?谢谢 您很可能遇到浏览器缓存问题。尝试清除缓存,例如,检查Chrome开发工具网络选项卡或Firefox开发工具设置中的禁用缓存。这应该可以解决问题。谢谢你的帮助!我试过了,但没有帮助。我收到一个加载资源失败:net::ERR\u NAME\u NOT\u RESOLVED
错误(可能这个浏览器错误有帮助?)。这表示DNS问题,仔细检查您的nginx配置中的域名是否没有输入错误。谢谢-这是否意味着我需要像使用example.com一样将www.example.com指向我的IP地址?(也许这是一个初学者的错误?)不,你只需要确保你的DNS将www.example.com和example.com解析为你服务器的IP。我猜你没有自己运行DNS,所以请与你的域名提供商确认一切正常。您可以使用nslookup example.com
或dig example.com
在命令行上直接查询DNS系统。您是否有www.example.com的DNS记录?