如何动态反向代理 nginx 桌面和移动?

如何动态反向代理 nginx 桌面和移动?

proxy_pass domain.xyz;如果用户使用桌面访问并且使用移动设备访问,如何进行反向代理proxy_pass mobile.domain.xyz;?我使用 nginx 作为反向 Web 服务器。这是我的示例代码:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/nginx/ssl/cert.crt;
    ssl_certificate_key /etc/nginx/ssl/cert.key;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
    ssl_session_tickets off;

    # modern configuration
    ssl_protocols TLSv1.3;
    ssl_prefer_server_ciphers off;

    # HSTS (ngx_http_headers_module is required) (63072000 seconds)
    add_header Strict-Transport-Security "max-age=63072000" always;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;

    # verify chain of trust of OCSP response using Root CA and Intermediate certs
    ssl_trusted_certificate /etc/nginx/ssl/cert-ca.crt;

    # replace with the IP address of your resolver
    resolver 1.1.1.1 1.0.0.1;

    location ~ /.well-known {
        root /var/www/html;
    }

    #Custom Sitemap
    #location ~ ^/(sitemap.xml) {
    #    root /var/www/html;
    #}

    #Google verification
    #location ~ ^/(googlee1a07b36e5db19e8.html) {
    #    root /var/www/html;
    #}

    location / {
        proxy_set_header Accept-Encoding "";
        sub_filter_once off;
        sub_filter_types *;
        #sub_filter "'http:'" "'https:'";
        sub_filter 'www.domain.xyz' '$host';
        sub_filter 'domain.xyz' '$host';

        proxy_redirect https://www.domain.xyz https://$host;
        proxy_redirect http://www.domain.xyz https://$host;

        proxy_ssl_server_name on;
        proxy_pass http://www.domain.xyz;
        proxy_cache_bypass  $http_upgrade;

        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_set_header X-Forwarded-Host   $host;
        proxy_set_header X-Forwarded-Port   $server_port;
    }
}

我可以使用 nginx 制作动态反向代理吗?谢谢帮助

相关内容