我有 ubuntu 14.04 服务器、nginx 1.10.1 和几个带有 proxy_pass 的站点。一切正常,直到我想添加另一个用于静态内容的站点。当我尝试连接到我的新站点时,我突然被重定向到我的一个旧站点,就像新站点的服务器配置为空一样。此外:我决定制作新的默认配置,但它不起作用!这是我的配置:
#new site for static content
server {
listen mypublicIP:80;
access_log /var/log/nginx/dev_proxy_access.log ;
error_log /var/log/nginx/dev_proxy_error.log;
server_name repdev.mydomain.com;
index test.txt;
root /data/replay;
}
#default config
server {
listen 80 default_server;
server_name _;
error_log /var/log/nginx/default_server_error.log;
access_log /var/log/nginx/default_server_access.log;
return 503 'Missed!';
}
并重定向到此网站:
#force redirect to https
server {
listen mypublicIP:80;
server_name crowd.mydomain.com;
return 302 https://crowd.mydomain.com$request_uri;
}
#proxy to localbackend
server {
listen mypublicIP:443 ssl;
server_name crowd.mydomain.com;
ssl_certificate /etc/nginx/ssl/crowd.crt;
ssl_certificate_key /etc/nginx/ssl/crowd.key;
client_max_body_size 100m;
access_log /var/log/nginx/crowd_access.log;
error_log /var/log/nginx/crowd_error.log;
location / {
proxy_pass http://mylocalbackend;
}
}
这是对我的新网站进行 curl 的结果:
MyaPC:~ Myafk$ curl -v repdev.mydomain.com
* Rebuilt URL to: repdev.mydomain.com/
* Trying mypublicIP...
* Connected to repdev.mydomain.com (mypublicIP) port 80 (#0)
> GET / HTTP/1.1
> Host: repdev.mydomain.com
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.10.1
< Date: Wed, 06 Jul 2016 12:46:53 GMT
< Content-Type: text/html
< Content-Length: 185
< Connection: keep-alive
< Location: https://crowd.mydomain.com/
<
有什么建议么?
答案1
好的,我找到了解决方案。我的一些网站配置已监听 80;我向它们添加了我的公共地址,现在一切正常。我认为这可能是与所有接口的多重绑定冲突。谢谢,serverfault ^_^