server {
listen 80;
listen [::]:80;
server_name localhost;
#root /etc/nginx/html;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /api1 {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' $http_access_control_request_headers;
add_header 'Access-Control-Allow-Methods' *;
if ($request_method = 'OPTIONS') {
return 200;
}
alias /usr/api1;
# 用于vue打包发布后的路由跳转
try_files $uri $uri/ /index.html @router;
index index.html index.htm;
}
location /api2 {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' $http_access_control_request_headers;
add_header 'Access-Control-Allow-Methods' *;
if ($request_method = 'OPTIONS') {
return 200;
}
alias /usr/api2;
try_files $uri $uri/ /index.html @router;
index index.html index.htm;
}
location /api3 {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' $http_access_control_request_headers;
add_header 'Access-Control-Allow-Methods' *;
if ($request_method = 'OPTIONS') {
return 200;
}
alias /usr/api3;
try_files $uri $uri/ /index.html @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
location /api {
proxy_set_header x-forwarded-for $remote_addr;
proxy_pass http://127.0.0.1:7001/api;
}
location / {
proxy_pass http://127.0.0.1:7001;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Ngxin请求转发示例
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 响应头:response.sendError(int sc,String msg); 获取请求URL 请求转发和请...
- 用户向服务器发送了一次HTTP请求,该请求可能会经过多个信息资源处理以后才返回给用户,各个信息资源使用请求转发机制...
- Table of Contents HTTP 请求方法[#http-%E8%AF%B7%E6%B1%82%E6%9...