RSS Amplifier

Ivan Derevianko's Blog Feed · Nov 7, 2016

Nginx Server Blocks (Virtual Hosts) Example Template

0
Sign in to vote or save

Ivan Derevianko · Ivan Derevianko

nginxHere is an example of the nginx server block (Virtual Hosts) which you can use to host multiple web sites on the same server.

Just replace example.com with your own domain name. Do not forget to create all required folders and sent right permissions.

Copy one of those templates to the /etc/nginx/sites-available/example.com

Proxy example

# Ivan Derevianko aka druss http://ivanderevianko.com
# Force without domain domain without www
server {
    server_name  www.example.com;
    listen 80;
    rewrite ^(.*) http://example.com$1 permanent;
}
# Main server
server {
    server_name  example.com;
    listen 80;
    root /var/example.com/www;
    access_log /var/example.com/logs/access.log;
    error_log /var/example.com/logs/error.log;
    location / {
        proxy_pass http://localhost:5000;
	proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Php-fpm example

# Ivan Derevianko aka druss http://ivanderevianko.com
# Force without domain domain without www
server {
    server_name  www.example.com;
    listen 80;
    rewrite ^(.*) http://example.com$1 permanent;
}
# Main server
server {
    server_name  example.com;
    listen 80;
    root /var/example.com/www;
    access_log /var/example.com/logs/access.log;
    error_log /var/example.com/logs/error.log;
    client_max_body_size 128M;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

Read the original on ivanderevianko.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.