你能在 nginx 配置中将多个代理作为位置吗?

你能在 nginx 配置中将多个代理作为位置吗?

我有几个 Web 应用,我想用一个 URL 来代理。这是我的 nginx.conf

server {
    listen 443 ssl;

    server_name webapps.mysite.com 192.168.5.28;

    access_log  /var/log/nginx/webapps_access.log;
    error_log   /var/log/nginx/webapps_errors.log;

    ssl_certificate /etc/letsencrypt/live/webapps.mysite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/webapps.mysite.com/privkey.pem; # managed by Certbot


    location /casaos {
        proxy_pass http://192.168.5.165:81;
        proxy_intercept_errors on;
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        # access_log off;

    }

    location /guacamole/ {
        proxy_pass http://192.168.5.44:8080;
        proxy_intercept_errors on;
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        # access_log off;
    }

    location /apps {
        # The following configurations must be configured when proxying to Kasm Workspaces

        # WebSocket Support
        proxy_set_header        Upgrade $http_upgrade;
        proxy_set_header        Connection "upgrade";

        # Host and X headers
        proxy_set_header        Host $host;
        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;

        # Connectivity Options
        proxy_http_version      1.1;
        proxy_read_timeout      1800s;
        proxy_send_timeout      1800s;
        proxy_connect_timeout   1800s;
        proxy_buffering         off;
        proxy_intercept_errors on;

        # Allow large requests to support file uploads to sessions
        client_max_body_size 10M;

        # Proxy to Kasm Workspaces running locally on 8443 using ssl
        proxy_pass https://192.168.5.40;
    }
}

如果我使用 web 应用程序的 ip,它们就可以工作;

HTTP://192.168.5.165:81

HTTP://192.168.4.44:8080

HTTP://192.168.5.40

但在我的网站配置中,唯一可以运行的网站是鳄梨酱应用程序。

HTTP://webapps.mysite.com/guacamole/

另一个给了我 404。

HTTP://webapps.mysite.com/apps

HTTP://webapps.mysite.com/casaos

我该如何解决出现 404 的问题?日志也没有提供任何信息,我只是尝试访问我的网站

还有一件事,如果我只将一个网站代理为 /,它们就可以工作。

location / {
    proxy_pass http://192.168.5.165:81;
    proxy_intercept_errors on;
    proxy_buffering off;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    # access_log off;

}

因此,这再次困扰着我,因为我无法托管多个 Web 应用程序。

相关内容