如下两个代理,分别将 yuwei.cc 代理到 127.0.0.1:9000、yuwei.cc/api 代理到 127.0.0.1:9501:

    1. server {
    2. listen 80;
    3. server_name yuwei.cc;
    4. access_log logs/book.log;
    5. error_log logs/book.error;
    6. location / {
    7. root html;
    8. index index.php index.html;
    9. proxy_pass http://127.0.0.1:9000; #这里的端口记得改成项目对应的哦
    10. }
    11. #将 /api 请求转发给 http://127.0.0.1:9501 处理
    12. location /api {
    13. proxy_pass http://127.0.0.1:9501; #这里的端口记得改成项目对应的哦
    14. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    15. proxy_set_header X-Forwarded-Proto $scheme;
    16. proxy_set_header X-Forwarded-Port $server_port;
    17. }
    18. }