nginx配置实践笔记<二>

一、前端代理配置示例

server {
      listen    80;
      server_name  xxx.xxxx.com www.xxx.xxxx.com;
      access_log on;
      charset utf-8;

     location / {
        root /home/test/build;
        index index.html index.htm;
        # error_page 403 /index.html;
        # error_page 404 /index.html;
        try_files $uri /index.html; #加上这句解决react 当前路由下 刷新 报404的问题
        if (!-e $request_filename) {
          rewrite ^.+test/(.*) /index.html last;
          break;
        }
     }
     
     # 前端路由代理
     location /api {
        rewrite ^.+api/?(.*)$ /$1 break;
        proxy_pass http://xxx.xxxx.com;
     }
	
	 # 错误处理重定向相对nginx路径下 html/50x.html路径
     error_page 500 502 503 504 /50x.html;
     
     # 错误处理404页面处理方式,具体根据情况配置,暴力解决线上404问题,但不能从根本上解决
     error_page 404 /index.html;
     # 自定义错误页面线上地址
     error_page 400  http://www.baidu.com;
     location = /index.html {
       root /home/test/build;
     }

     location = /50x.html {
       root html;
     }
     # 解决 GET /favicon.ico HTTP/1.1 404问题
     location /favicon.ico{
	    return 200;
	    access_log off;
     }
 }
   `和上面处理一样`
   # /favicon.ico” failed (2: No such file or directory)
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

nginx基础安装使用配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值