Nginx 多 Laravel 项目配置


http {
    access_log  /dev/null;
    include mime.types;
    default_type application/octet-stream;

    sendfile on;

    keepalive_timeout 120;

    client_header_buffer_size 256k;
    large_client_header_buffers 4 256k;
    client_max_body_size 200M;
    client_body_buffer_size 512k;

    map $host $dir {
        ~^(.*)$ /Home/user/laravel/$1/public;
    }

    server {
        listen 80;
        listen 443 ssl http2;
        ssl_certificate /home/ssl.crt;
        ssl_certificate_key /home/ssl.key;

        server_name  _;
        root $dir;

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

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
            fastcgi_param  QUERY_STRING       $query_string;
            include        fastcgi_params;
        }

        location = /debug {
            default_type text/plain;
            return 200 $dir;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

/etc/hosts 中, 添加如下

127.0.0.1 a.site.com
127.0.0.1 b.site.com

然后

  • /Home/user/laravel/a.site.com/ 部署 a.site.com 的项目
  • /Home/user/laravel/b.site.com/ 部署 b.site.com 的项目

重点在那个 map 指令上. 具体用法大家自己看文档去吧.

本作品采用《CC 协议》,转载必须注明作者和本文链接
www.anquanssl.com 安全SSL
本帖由系统于 7年前 自动加精
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 3
qiuyuhome

不错,这样设置以后。多个项目可以不用设置nginx了,开发更方便。👍🏻。

7年前 评论

早年间也实现过一个二级域名的 Nginx 配置:https://wi1dcard.cn/snippets/laravel-nginx...,配置一个泛解析即可。

另外,macOS 可以使用 Valet 作为全套解决方案,自带 Dnsmasq。

7年前 评论

都是public目录可以这么搞

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!