如何在nginx中为特殊路径设置反向代理?
如何在nginx中为特殊路径设置反向代理 在my Nignx的default.conf中:如何在nginx中为特殊路径设置反向代理?,nginx,reverse-proxy,Nginx,Reverse Proxy,如何在nginx中为特殊路径设置反向代理 在my Nignx的default.conf中: server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { # root /usr/share/nginx/html; roo
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
# root /usr/share/nginx/html;
root /var/www/html/website;
index index.html index.htm;
try_files $uri $uri/ /index.html;
proxy_pass http://107.120.30.76:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
我只知道如何配置/
根目录,如何配置特殊路径
例如我请求
http://107.120.30.76/api/*
我想转到http://107.120.30.76:8000/api/*
。如何配置?您可以将以下配置添加到服务器配置中:
location /api/ {
# root /usr/share/nginx/html;
root /var/www/html/website;
index index.html index.htm;
try_files $uri $uri/ /index.html;
proxy_pass http://107.120.30.76:8001/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}