laravel nginx 路由重写

1、因为在配置了阿里云的负载均衡(SLB),将/fat转发到测试环境,以此用同一个域名来区分生产环境与测试环境,所以需要在测试环境中重写路由来去除路由中的/fat

2、修改nginx对应域名的配置文件

fastcgi_param参考:FastCGI中fastcgi_param 详细说明 - 风与叶子 - 博客园

server {
    listen 80;
    server_name xxx.com;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    charset utf-8;
    
    if ($request_uri ~ /fat/(.*)$) {
        set $new_request_uri /$1;
        set $new_query_string $query_string;
        set $new_request_method $request_method;
    }
    
    root /xxx/xxx/xxx;     # 项目目录
    index index.php;
   # error_page 404 /index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    location ~ \.php$ {
        fastcgi_pass docker_container:9000;    # 对应项目的docker容器,这里主要是Nginx和PHP-FPM的进程间通信
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REQUEST_URI $new_request_uri;
        fastcgi_param QUERY_STRING $new_query_string;
        fastcgi_param REQUEST_METHOD $new_request_method;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }


}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值