Skip to content

Instantly share code, notes, and snippets.

@ardnor
Forked from folivares/laravel_nginx.md
Created January 30, 2018 15:04
Show Gist options
  • Save ardnor/3d18ba1b2518bfa71c17e189a20589e2 to your computer and use it in GitHub Desktop.
Save ardnor/3d18ba1b2518bfa71c17e189a20589e2 to your computer and use it in GitHub Desktop.

Revisions

  1. @folivares folivares revised this gist Nov 6, 2015. 1 changed file with 5 additions and 8 deletions.
    13 changes: 5 additions & 8 deletions laravel_nginx.md
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,6 @@ Prerequisites
    * Laravel 5.1
    * Nginx 1.8

    ___

    Default Server Block
    -------------------------
    Nginx Server Blocks are located in /etc/nginx/sites-available. The filename for default block is "default".
    @@ -50,8 +48,6 @@ server {
    }
    ```

    ___

    Other Domains Server Blocks
    -----------------------------------
    Other blocks are located in same folder of default block (/etc/nginx/sites-available). Filename for each domain is domain_name.
    @@ -66,17 +62,18 @@ server {
    root "/var/www/domain_name/public";
    index index.html index.htm index.php;
    # charset of Content-Type response header field
    # charset of "Content-Type" response header field
    charset utf-8;
    # set the maximum allowed size of the client request body
    #client_max_body_size 100m;
    # log settings
    # log settings
    access_log off;
    error_log /var/log/nginx/domain_name-error.log error;
    # turn off access logs and prevents logging an error if robots.txt and favicon.ico are not found
    # turn off access logs and prevents logging
    # an error if robots.txt and favicon.ico are not found
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }
    @@ -104,7 +101,7 @@ server {
    fastcgi_read_timeout 300;
    }
    # block access to .htaccess files
    # block access to .htaccess files
    location ~ /\.ht {
    deny all;
    }
  2. @folivares folivares renamed this gist Nov 6, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @folivares folivares created this gist Nov 6, 2015.
    113 changes: 113 additions & 0 deletions laravel_nginx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,113 @@
    Nginx Server Blocks configuration to run more than one Laravel 5.1 web-app off of a single Linux server

    Prerequisites
    ----------------
    * PHP package: php5-fpm php5-mcrypt php5-mysql
    * Laravel 5.1
    * Nginx 1.8

    ___

    Default Server Block
    -------------------------
    Nginx Server Blocks are located in /etc/nginx/sites-available. The filename for default block is "default".
    ```
    server {
    # default server specification
    listen 80 default_server;

    # site accessible from http://domain_or_ip
    server_name domain_or_ip;

    # file location
    root /var/www/html;
    index index.php index.html index.htm;

    # check if a file or directory index file exists, else route it to 404 error page.
    location / {
    try_files $uri $uri/ =404;
    }

    # error pages
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }

    # handle execution of PHP files
    # set php5-fpm socket
    # tell NGINX to proxy requests to PHP FPM via the FCGI protocol
    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    }
    ```

    ___

    Other Domains Server Blocks
    -----------------------------------
    Other blocks are located in same folder of default block (/etc/nginx/sites-available). Filename for each domain is domain_name.
    ```
    server {
    listen 80;

    # site accessible from domain_name
    server_name domain_name;

    # file location (note the "public" folder of Laravel)
    root "/var/www/domain_name/public";
    index index.html index.htm index.php;

    # charset of Content-Type” response header field
    charset utf-8;

    # set the maximum allowed size of the client request body
    #client_max_body_size 100m;

    # log settings
    access_log off;
    error_log /var/log/nginx/domain_name-error.log error;

    # turn off access logs and prevents logging an error if robots.txt and favicon.ico are not found
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }


    # check if a file or directory index file exists,
    # else pass the request to the index.php as a query parameter.
    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }

    # handle execution of PHP files
    # set php5-fpm socket
    # tell NGINX to proxy requests to PHP FPM via the FCGI protocol
    location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    }

    # block access to .htaccess files
    location ~ /\.ht {
    deny all;
    }

    }
    ```