我的问题类似于一个here。但在我的例子中,我使用的是Godaddy公共域名,它指向一个公共地址,并被路由到我的服务器,其中有固定的私有ip地址(192.168.0.145).If我在nginx.conf中将服务器名指定为domain.com,什么都不起作用。但是,如果我给本地域或服务器提供私有ip,即使我浏览http://domain.com,它也能正常工作。我甚至尝试添加域名到我的主机失败127.0.0.1 domain_name,但没有运气。我在网上搜索过,但从来没有看到有人把私有ip或本地域名放在nginx.conf中而不是域名地址。我真的需要将所有http://domain.name重定向到http://www.domain.com,但是由于我不能放置我的域名,所以我找不到解决方案。我是不是漏掉了什么明显的东西?
server {
listen 80;
server_name 192.168.0.145;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080;
}
}发布于 2013-05-14 02:48:28
这是一个棘手的解决方案,您定义两个服务器,而非www重定向到www。
server{
server_name domain.com;
return 301 $scheme://www.domain.com$request_uri
}
server{
server_name www.domain.com;
#the rest of your normal config goes here
}所有非www将与server#1匹配,并将被定向到与server#2匹配的格式
发布于 2013-05-06 14:28:20
在您的服务器部分中
server_name www.domain.com domain.com 192.168.0.145;
if ($host !~* ^www\.domain\.com$ ) {
rewrite ^(.*)$ http://www.domain.com$1 permanent;
}https://stackoverflow.com/questions/16393056
复制相似问题