Я указал место / Таня по адресу http://52.221.238.24/tanya;, Я тоже хочу, чтобы / tanya / t / указывала на тот же IP.
Однако мне нужно указать / tanya / dynamic_generated, чтобы указать на другой IP-адрес. http://127.0.53.53:3000;
Как это возможно с помощью nginx.
Я пробовал следующее:
location / {
proxy_pass http://127.0.53.53:3000;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /tanya/t/ {
proxy_pass http://52.221.238.24/tanya/t/;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /tanya {
proxy_pass http://127.0.53.53:3000;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location = /tanya/ {
proxy_pass http://52.221.238.24/tanya;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Я придумал решение. Проблема заключалась в том, что мой маршрут nodeJs конфликтовал с местоположениями Nginx. Решение: я создал еще один подкаталог для моего маршрута nodeJs. Вроде примерно следующее:
Конфигурация Nginx:
location / {
proxy_pass http://127.0.53.53:3000;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /tanya/t/ {
proxy_pass http://52.221.238.24/tanya/t/;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /tanya/amp/ {
proxy_pass http://127.0.53.53:3000;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /tanya {
proxy_pass http://52.221.238.24/tanya;
include /etc/nginx/proxy_params;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
По-видимому, Nginx сначала ищет САМЫЙ ДЛИННЫЙ uri местоположения. В результате он сначала ищет «/ tanya / amp /» и «/ tanya / t /» и указывает на их соответствующие IP-адреса.
Если ни один из них («/ amp» или «/ t») не запрошен, он ищет «/ tanya / anyting else» и указывает на IP, указанный в местоположении «/ tanya».
Таким образом, я внес еще одно изменение в свой маршрут (nodeJs):
app.get('/tanya/amp/:questionUrl',(req,res)=>{
let ampListUrl = req.ampListBase+'/tanya/t';
res.render('./html/questionsTanya.ejs', {
question: question,
ampListUrl:ampListUrl
});
});