Skip to content

Commit 68ffdba

Browse files
authored
Update README.md
Signed-off-by: 前端市界 <wkylin.w@gmail.com>
1 parent 50d9d2a commit 68ffdba

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ npm version [| major | minor | patch | premajor | preminor | prepatch | prerelea
431431
listen 8081;
432432
#server_name localhost;
433433
server_name www.pro.react.admin.com;
434-
434+
# 静态资源
435435
location / {
436436
root /usr/local/var/www/pro-react-admin;
437437
index index.html index.htm;
@@ -440,10 +440,27 @@ npm version [| major | minor | patch | premajor | preminor | prepatch | prerelea
440440
add_header Cache-Control no-cache;
441441
# proxy_pass http://localhost:3000;
442442
}
443-
# 接口转发,如果需要的话
444-
#location ~ ^/api {
445-
# proxy_pass http://www.wkylin.com;
446-
#}
443+
# API代理
444+
location /api/ {
445+
proxy_pass https://api.example.com/;
446+
proxy_set_header Host $host;
447+
proxy_set_header X-Real-IP $remote_addr;
448+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
449+
proxy_set_header X-Forwarded-Proto $scheme;
450+
451+
# 允许跨域配置
452+
add_header Access-Control-Allow-Origin $http_origin;
453+
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
454+
add_header Access-Control-Allow-Headers 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
455+
add_header Access-Control-Allow-Credentials 'true';
456+
457+
if ($request_method = 'OPTIONS') {
458+
add_header Access-Control-Max-Age 86400;
459+
add_header Content-Length 0;
460+
add_header Content-Type text/plain;
461+
return 204;
462+
}
463+
}
447464
location @rewrites {
448465
rewrite ^(.+)$ /index.html break;
449466
}

0 commit comments

Comments
 (0)