eu quero me conectarexemplo.com:80eexemplo.com:82para um site específico por meio de proxy reverso.
localhost/api/comprar/ ->http://exemplo.com:80/
localhost/api/sell/ ->http://exemplo.com:82/
Eu configurei o arquivo de configuração conforme abaixo.
server {
listen 80;
server_name localhost;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location = /api/buy {
return 302 /api/buy/;
}
location /api/buy/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://example.com:80/;
proxy_redirect off;
}
location = /api/sell {
return 302 /api/sell/;
}
location /api/sell/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://example.com:82/;
proxy_redirect off;
}
}
Mas se eu conectar/api/buy e/api/sell, recebo um erro 404 não encontrado.
Abaixo está o conteúdo do arquivo error.log.
connect() failed (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /api/ HTTP/1.1", upstream: "http://example.com/api/buy/", host: "localhost"
Ao usar uma porta diferente, confirmei que a configuração funciona bem.
Quero configurá-lo para a mesma porta, mas existe alguma maneira?
Responder1
a melhor maneira é mudadaproxy_passhttp://exemplo.com:80/para proxy_passhttp://example.com:80/api/buy/
location = /api/buy {
return 302 /api/buy/;
}
location /api/buy/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://example.com:80/api/buy/;
proxy_redirect off;
}