记录单页web应用配置

    1. server {
    2. listen 8166;
    3. server_name 127.0.0.1 localhost m.bank-pay.com;
    4. charset utf-8;
    5. # 成功日志
    6. access_log logs/xueyou-admin.log;
    7. # 错误日志
    8. error_log logs/xueyou-admin_error.log;
    9. index index.html;
    10. # 变量设置,设置公共路径
    11. set $root /home/servers/xueyou-admin/website/;
    12. fastcgi_intercept_errors on;
    13. location / {
    14. index index.html;
    15. root $root;
    16. # 单页应用返回固定内容
    17. try_files $uri /index.html;
    18. }
    19. location ^~ /api {
    20. # 重写路径,去掉/api
    21. rewrite ^/api/(.*) /$1 break;
    22. proxy_pass http://192.168.1.26:8053;
    23. proxy_set_header Host $host;
    24. proxy_set_header X-Real-IP $remote_addr;
    25. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    26. proxy_set_header X-Forwarded-Proto https;
    27. proxy_next_upstream off;
    28. proxy_connect_timeout 30;
    29. proxy_read_timeout 300;
    30. proxy_send_timeout 300;
    31. }
    32. location ^~ /captcha {
    33. proxy_pass http://192.168.1.26:8053;
    34. proxy_set_header Host $host;
    35. proxy_set_header X-Real-IP $remote_addr;
    36. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    37. proxy_set_header X-Forwarded-Proto https;
    38. proxy_next_upstream off;
    39. proxy_connect_timeout 30;
    40. proxy_read_timeout 300;
    41. proxy_send_timeout 300;
    42. }
    43. location ^~ /file {
    44. proxy_pass http://192.168.1.26:8053;
    45. proxy_set_header Host $host;
    46. proxy_set_header X-Real-IP $remote_addr;
    47. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    48. proxy_set_header X-Forwarded-Proto https;
    49. proxy_next_upstream off;
    50. proxy_connect_timeout 30;
    51. proxy_read_timeout 300;
    52. proxy_send_timeout 300;
    53. }
    54. error_page 500 502 503 504 403 404 = @errpage;
    55. location @errpage {
    56. index index.html;
    57. root $root;
    58. # 单页应用返回固定内容
    59. try_files $uri /index.html;
    60. }
    61. }