我有我的网站上的IP 1.2.3.4
在我的域名提供商,我有onesite.com和anothersite.com指向1.2.3.4
使用Nginx,我configuration了两个站点:
server { listen 1.2.3.4:80; server_name www.oneserver.com; rewrite ^(.*) http://onserver.com$1 permanent; } server { listen 1.2.3.4:80; server_name onserver.com; location / { fastcgi_pass 127.0.0.1:8878; [..]
和:
server { listen 1.2.3.4:80; server_name myapp.anotherserver.com; location / { fastcgi_pass unix:/tmp/myapp.sock; [..]
当我访问myapp.anotherserver.com时,我被redirect到oneserver.com
任何帮助?
正如user186340
指出的那样,你的configuration片段看起来不错,访问端口80
myapp.anotherserver.com
应该在你提供的第三个块中。 如果它不像你所描述的那样工作,那可能是因为它没有被加载。
nginx -t
来validation你的configuration HUP
信号发送到nginx主进程时,监视您的错误日志,以发现任何popup的错误消息 nginx -T
将加载的configuration转储到标准输出 如果以下所有内容都是正确的,那么您可能会将显示的configuration与您实际使用的显示configuration进行比较。
问题是Nginxselect默认的服务器,并将其用于没有明确定义服务器的任何请求。 我的解决方法是定义一个什么都不做的默认服务器。
# This just prevents Nginx picking a random default server if it doesn't know which # server block to send a request to server { # You can add 443/ssl if you need to listen 80 default_server; server_name _; access_log off; log_not_found off; # "I'm a teapot", effectively "go away" https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error # Code 403 (forbidden), 410 (gone) or 501 (not implemented) is probably a better choice https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error return 418; }