Nginx 配置二级虚拟目录访问 Laravel 重写

Posted ifme

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx 配置二级虚拟目录访问 Laravel 重写相关的知识,希望对你有一定的参考价值。

server 
    listen          80;
    server_name    _;
    root            /opt/sites;
    index           index.php index.html index.htm;
    etag on;

    gzip on;
    gzip_vary on;
    gzip_http_version 1.0;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_comp_level 2;
    gzip_disable msie6;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/xml+rss;

    client_max_body_size 110m;
    client_body_buffer_size 1024k;

    keepalive_timeout   60;

    sendfile on;
    sendfile_max_chunk 512k;
    tcp_nopush on;
    tcp_nodelay on;


# 此处配置二级目录站点
   location  /son
        alias   /opt/sites/cms/public;
        index index.html index.php;

        try_files $uri $uri/ /index.php?$query_string;

        location ~ \.php$ 
                if (!-f $request_filename) 
                        return 404;
                

                fastcgi_pass        unix:/tmp/php-fpm-72.sock;
                fastcgi_index       index.php;
                fastcgi_param       SCRIPT_FILENAME $request_filename;
                include             fastcgi_params;
        
    

  #此处是根目录下配置laravel站点
    location / 
        try_files $uri $uri/ /index.php?$query_string;
    

    location ~ \.php$ 
        fastcgi_pass        unix:/tmp/php-fpm-72.sock;
        fastcgi_index       index.php;
        fastcgi_param       SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include             fastcgi_params;
    

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

这次遇到的问题是在访问http://localhost/son访问不了index.php,而index.html可以访问。在参考了https://laravel-china.org/articles/14235/nginx-configuring-two-level-virtual-directory-access-laravel-rewrite解决.

以上是关于Nginx 配置二级虚拟目录访问 Laravel 重写的主要内容,如果未能解决你的问题,请参考以下文章

nginx 反向代理 虚拟二级目录

Nginx怎么绑定二级域名 绑了没法PHP

NGINX-二级域名

nginx代理访问不了二级目录下的静态资源

Nginx配置二级目录/路径 映射不同的反向代理和规避IP+端口访问

通过Nginx为网站配置二级域名并访问指定项目