0
点赞
收藏
分享

微信扫一扫

laravel nginx 路由重写

炽凤亮尧 2022-02-10 阅读 75

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

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

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

server {
    listen 80;
    server_name xxx.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;

    location /fat {

        root /xxx/xxx/xxx;    # 项目目录
        index index.php;        

        if ($request_uri ~ /fat/(.*)$) {
             set $new_request_uri /index.php/$1;
             set $new_query_string $query_string;
             set $new_request_method $request_method;
        }

        #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; }

        error_page 404 /index.php;

        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;
        }

    }

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

}

 

举报

相关推荐

Laravel路由

Laravel-【路由】

laravel路由设置

Nginx URL 重写

nginx:Url重写

nginx url重写

laravel nginx 配置

0 条评论