Nginx
在 nginx 中刪除 Java 應用程序的子路徑(上下文根)
該應用程序位於 Payara 伺服器上並具有上下文根
nocodeapp-web-front-1.0
我不想在 url 中有這個上下文根。此 nginx 配置為應用程序的頁面提供了預期的結果
index
(它位於https://test.nocodefunctions.com
):upstream payara { least_conn; server localhost:8080 max_fails=3 fail_timeout=5s; server localhost:8181 max_fails=3 fail_timeout=5s; } server { if ($host = test.nocodefunctions.com) { return 301 https://$host$request_uri; } listen 80; access_log /var/log/nginx/payara-access.log; error_log /var/log/nginx/payara-error.log; client_max_body_size 100M; server_name test.nocodefunctions.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name test.nocodefunctions.com; client_max_body_size 100M; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; location /nocodeapp-web-front-1.0 { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto https; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_no_cache $cookie_nocache $arg_nocache$arg_comment; proxy_no_cache $http_pragma $http_authorization; proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment; proxy_cache_bypass $http_pragma $http_authorization; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host:$server_port; add_header Access-Control-Allow-Origin *; proxy_set_header Access-Control-Allow-Origin *; proxy_pass http://payara$request_uri; } location = / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto https; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://payara/nocodeapp-web-front-1.0$request_uri$is_args$args; } ssl_certificate /etc/letsencrypt/live/xxxxxx/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/xxxxxx/privkey.pem; # managed by Certbot }
但是,當我們通過點擊“Go”按鈕在應用程序中導航時,頁面
/choosefunction.html
顯示為:https://test.nocodefunctions.com/nocodeapp-web-front-1.0/choosefunction.html
…子路徑
nocodeapp-web-front-1.0
再次出現?我怎樣才能得到:
https://test.nocodefunctions.com/choosefunction.html
您需要在應用程序配置中指定應用程序的根 URL。這將使應用程序為連結和資源生成正確的 URL。