2

我有一个 nginx 监听端口 80 的服务器,并且有多个域名的配置,应该代理到不同端口的连接。

这是我的配置文件:

域1

#This is for redirecting everyone from www.domain.com to domain.com
server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name www.domain1.com;

    return 301 $scheme://domain1.com$request_uri;
}

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        server_name domain1.com;

        location / {
                proxy_pass http://localhost:8081/;
                proxy_set_header  X-Real-IP  $remote_addr;
        }
}

域2

#This is for redirecting everyone from www.domain.com to domain.com
server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name www.domain2.com;

    return 301 $scheme://domain2.com$request_uri;
}

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        server_name domain2.com;

        location / {
                proxy_pass http://localhost:8090/;
                proxy_set_header  X-Real-IP  $remote_addr;
        }
}

域3

#This is for redirecting everyone from www.domain.com to domain.com
server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name www.domain3.com;

    return 301 $scheme://domain3.com$request_uri;
}

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        server_name domain3.com;

        location / {
                proxy_pass http://localhost:8091/;
                proxy_set_header  X-Real-IP  $remote_addr;
        }
}

所有这些配置文件(像往常一样)位于/etc/nginx/sites-available/并符号链接到/etc/nginx/sites-enabled/

当我添加第一个文件时,一切都作为一种魅力,当我添加第二个文件时,它是相同的,在添加第三个文件后,当我尝试执行service nginx reloadorservice nginx restart或时,nginx 停止给我任何消息service nginx start

它响应service nginx stopservice nginx status。显然这些功能有效,但这些先决条件中的其他功能没有响应并且不做任何事情。下面的输出只是从我的控制台复制粘贴。

# service nginx status
[ ok ] nginx is running.
# service nginx reload
# service nginx restart
# service nginx stop
[ ok ] Stopping nginx: nginx.
# service nginx start
# service nginx status
[FAIL] nginx is not running ... failed!
#

如果我删除到第三个文件的符号链接,一切都会再次完美运行。

那么问题来了——我的设置有问题吗?还是我的逻辑?还是使用 nginx?

环境是:

- Debian Squeeze x64
- Nginx version 1.2.6
4

1 回答 1

1

您遇到的症状表明您的 nginx 配置与第 3 个文件不正确,这就是重新加载失败的原因

的输出nginx -t应该告诉您配置中的问题所在。

于 2013-03-28T11:06:47.647 回答