Nginx 多 Laravel 專案配置

XiaohuiLam發表於2019-01-15

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 指令上. 具體用法大家自己看文件去吧.

Fine or not, never stop. Laravel 執行生命週期解析

相關文章