heihachi88
10/22/2014 - 11:37 AM

Nginx Server Blocks example | default dir: /usr/share/nginx/html | using /srv/www

Nginx Server Blocks example | default dir: /usr/share/nginx/html | using /srv/www

# creating domain directory
sudo mkdir -p /srv/www/example.com

# giving current user permission to that dir
sudo chown -R $USER:$USER /srv/www/example.com/

# creating server block
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com

# enabling domain by creating symlink in sites-enabled dir
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

# removing default block
sudo rm /etc/nginx/sites-enabled/default

# /etc/nginx/nginx.conf | uncomment
server_names_hash_bucket_size: 64;

# /etc/nginx/nginx.conf optimization - max connection worker_processes * worker_connections
worker_processes 8;
worker_rlimit_nofile 100000;

worker_connections 4000;
use epoll;
multi_accept on;

keepalive_timeout = 30s

# set client body size to 100M #
client_max_body_size 100M;

# RESTART NGINX
server {
    listen 80;

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

    server_name example.com www.example.com;

    location / {
        try_files $uri $uri/ =404;
    }
    
    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
          root /usr/share/nginx/www;
    }
    
    location ~ \.php$ {
        try_files $uri /index.php =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;
    }
}