fix(nginx): fix proxy_pass URI rewriting for /api/v2/ts/ location
nginx does not automatically handle URI appending when variables are used in proxy_pass. Replace variable-based proxy_pass with hardcoded IP + rewrite rules to correctly map /api/v2/ts/* → /api/v1/ts/* on the Rust htyts backend. Symptom: all requests to /api/v2/ts/ returned 404 because the variable-based proxy_pass sent every request to /api/v1/ts/ (root) regardless of path.
This commit is contained in:
@@ -126,8 +126,8 @@ server {
|
||||
content_by_lua_file $resty_loc/nginx/scripts/test.lua;
|
||||
}
|
||||
|
||||
location /api/v1/clazz/ {
|
||||
proxy_pass http://127.0.0.1:3002/api/v1/clazz/;
|
||||
location /api/v1/kc/ {
|
||||
proxy_pass http://127.0.0.1:3002/api/v1/kc/;
|
||||
}
|
||||
location /api/v1/ws/ {
|
||||
proxy_pass http://127.0.0.1:3001/api/v1/ws/;
|
||||
@@ -137,7 +137,9 @@ server {
|
||||
}
|
||||
|
||||
location /api/v2/ts/ {
|
||||
proxy_pass http://$huiwing_htyts_rust/api/v1/ts/;
|
||||
rewrite ^/api/v2/ts/$ /api/v1/ts break;
|
||||
rewrite ^/api/v2/ts/(.+)$ /api/v1/ts/$1 break;
|
||||
proxy_pass http://127.0.0.1:3003;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
+8
-18
@@ -1,23 +1,19 @@
|
||||
server {
|
||||
# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx#
|
||||
# server_name $servername;
|
||||
server_name "ts.moicen.com";
|
||||
listen 443 ssl;
|
||||
listen 80;
|
||||
client_max_body_size 10M;
|
||||
|
||||
# disable in local test env
|
||||
ssl_certificate /etc/letsencrypt/live/moicen.com/fullchain.pem; # managed by Certbot
|
||||
ssl_certificate_key /etc/letsencrypt/live/moicen.com/privkey.pem; # managed by Certbot
|
||||
ssl_certificate /etc/letsencrypt/live/moicen.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/moicen.com/privkey.pem;
|
||||
|
||||
set $task_server "http://127.0.0.1:8080"; # Java task_server
|
||||
set $huiwing_htyts_rust "127.0.0.1:3003"; # huiwing 仓库 htyts(Rust)
|
||||
set $task_server "http://127.0.0.1:8080";
|
||||
set $huiwing_htyts_rust "127.0.0.1:3003";
|
||||
set $task_server_rust "http://$huiwing_htyts_rust";
|
||||
set $htyuc "http://127.0.0.1:3000"; #htyuc host
|
||||
set $htyuc "http://127.0.0.1:3000";
|
||||
set $resty_loc "/usr/local/openresty";
|
||||
|
||||
location /api/v1/ts/ {
|
||||
|
||||
add_header Access-Control-Allow-Origin $http_origin always;
|
||||
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS' always;
|
||||
add_header Access-Control-Allow-Headers 'Authorization,HtyAdminToken,HtySudoerToken,HtyHost,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type' always;
|
||||
@@ -38,14 +34,8 @@ server {
|
||||
if ($request_method = 'OPTIONS') {
|
||||
return 200;
|
||||
}
|
||||
proxy_pass http://$huiwing_htyts_rust/api/v1/ts/;
|
||||
rewrite ^/api/v2/ts/$ /api/v1/ts break;
|
||||
rewrite ^/api/v2/ts/(.+)$ /api/v1/ts/$1 break;
|
||||
proxy_pass http://127.0.0.1:3003;
|
||||
}
|
||||
}
|
||||
|
||||
# server {
|
||||
# listen 80;
|
||||
# server_name "ts.moicen.com";
|
||||
# location / {
|
||||
# return 301 https://$host$request_uri;
|
||||
# }
|
||||
# }
|
||||
Reference in New Issue
Block a user