Skip to content

Instantly share code, notes, and snippets.

@h2rd
Forked from ashleydw/nginx.conf
Created September 20, 2020 09:56
Show Gist options
  • Save h2rd/cf7b7bf7e0b29d1e4bea378bc2ffedd1 to your computer and use it in GitHub Desktop.
Save h2rd/cf7b7bf7e0b29d1e4bea378bc2ffedd1 to your computer and use it in GitHub Desktop.

Revisions

  1. @ashleydw ashleydw revised this gist Jul 24, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ server {

    server_name example.com www.example.com;

    access_log/srv/www/example.com/logs/access.log;
    access_log /srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;

    root /srv/www/example.com/public;
  2. @ashleydw ashleydw created this gist Jul 24, 2014.
    55 changes: 55 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    server {
    listen 80 default_server;

    server_name example.com www.example.com;

    access_log/srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;

    root /srv/www/example.com/public;
    index index.php index.html;

    # serve static files directly
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
    log_not_found off;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
    rewrite ^/(.+)/$ /$1 permanent;
    }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
    rewrite ^/(.*)$ /index.php?/$1 last;
    break;
    }

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

    location ~* \.php$ {
    try_files $uri = 404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock; # may also be: 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    location ~ /\.ht {
    deny all;
    }
    }