nginx proxy_pass 到其他服务器到 index.html

nginx proxy_pass 到其他服务器到 index.html

我有两个节点,它们有对应的域名:server1.test.mydovps.net server2.test.mydovps.net。我想通过 proxy_pass 将上游从 server1.test.mydovps.net 传递到 server2.test.mydovps.net,然后查看 /var/www/server2.test.mydovps.net/index.html 的内容

虚拟主机配置为:server1.test.mydovps.net

upstream backend {
server server2.test.mydovps.net:80;
}

server {
    listen       80;
    server_name server1.test.mydovps.net www.server1.test.mydovps.net;

    access_log /var/log/nginx/server1.test.mydovps.net_access_log;
    error_log /var/log/nginx/server1.test.mydovps.net_error_log;

    location / {
        return 301 https://server1.test.mydovps.net$request_uri;
    }
}

server {

    # SSL server config

    listen       443 ssl http2 default_server;
    server_name server1.test.mydovps.net www.server1.test.mydovps.net;

    access_log /var/log/nginx/server1.test.mydovps.net_access_log;
    error_log /var/log/nginx/server1.test.mydovps.net_error_log;

    ssl_certificate     /etc/ssl/nginx/nginx-selfsigned.crt;
    ssl_certificate_key  /etc/ssl/nginx/nginx-selfsigned-privkey.key;

    location / {
        proxy_set_header Host backend;
        proxy_pass http://backend;
    }
}

和 server2.test.mydovps.net

server {
    listen       80;
    server_name server2.test.mydovps.net www.server2.test.mydovps.net;
    root /var/www/server2.test.mydovps.net;

    access_log /var/log/nginx/server2.test.mydovps.net_access_log;
    error_log /var/log/nginx/server2.test.mydovps.net_error_log;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

/var/www/server2.test.mydovps.net/index.html 的内容:

<h1> Hello! </h1>
<h3> From  <strong><em> server2 </em></strong> </h3>
<p> This is simple html to show everything is working fine</p>

当我到达https://server1.test.mydovps.net我希望看到我的 index.html 页面,但我看到“欢迎来到 nginx 页面”,然而当我到达http://server2.test.mydovps.net我看到了 html 页面。两个服务器可以互相访问。您能指出 nginx 配置中可能存在哪些错误吗?

相关内容