Centos7中具有nginx反向代理的多个域

时间:2017-05-23 20:58:34

标签: nginx proxy dns reverse

我想使用nginx前端反向代理在同一服务器上托管多个域,但我收到错误:“无法访问此站点domain1.example.com无法找到服务器DNS地址”。我可以访问maindomain.example.com但不能访问其他2个域:domain1.example.com和domain2.example.com。下面是我的maindomain.example.com.conf配置文件。

server {
            listen          80 default;
            server_name     maindomain.example.com;
         return 301      https://$host$request_uri;
    }

server {
            listen 80;
            listen 443 ssl;
            server_name domain1.example.com;

        ssl on;
        ssl_certificate     /etc/nginx/ssl/maindomain.example.com.crt;
        ssl_certificate_key /etc/nginx/ssl/maindomain.example.com.key;

        location / {
            proxy_set_header                Host                    $host:$server_port;
            proxy_set_header                X-Real-IP               $remote_addr;
            proxy_set_header                X-Forwarded-For         $proxy_add_x_forwarded_for;
            proxy_set_header                X-Forwarded-Proto       $scheme;
            proxy_pass                      http://localhost:8085;

            proxy_redirect                  http://127.0.0.1:8085   $scheme://domain1.example.com;
        }
}

server {
        listen 80;
        listen 443 ssl;
        server_name domain2.example.com;

        ssl on;
        ssl_certificate     /etc/nginx/ssl/maindomain.example.com.crt;
        ssl_certificate_key /etc/nginx/ssl/maindomain.example.com.key;

        location / {
                proxy_set_header                Host                    $host:$server_port;
                proxy_set_header                X-Real-IP               $remote_addr;
                proxy_set_header                X-Forwarded-For         $proxy_add_x_forwarded_for;
                proxy_set_header                X-Forwarded-Proto       $scheme;
                proxy_pass                      http://localhost:9009;

                proxy_redirect                  http://127.0.0.1:9009   $scheme://domain2.example.com;


    }
}

0 个答案:

没有答案