NGINX config help, Multiple Servers

Blackhawk1xx asked:

I am having an issue with NGINX , this could quite possibly be an easy fix then again could not be I just don’t know that much about NGINX.

I have my NGINX config below which works great. But I have 3 other hard drives with the same script that are set up with subdomains. So to make a long story short I need to add more listening servers I guess,
I have www1.example.com as first domain

and then I have www2.example.com etc. Each subdomain is on its own hard drive and I need to point nginx to each one of those hard drives. Is there a way to add the into the NGINX config?

Here is the config file.

#user  nobody;
worker_processes  4;
worker_rlimit_nofile 30000;
worker_rlimit_sigpending 32768;

error_log  logs/error.log  error;

#pid        logs/nginx.pid;


events {
    worker_connections  4096;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    access_log  off;
    limit_conn_log_level info;

    #sendfile       on;
    #tcp_nopush     on;
    reset_timedout_connection on;

    server_tokens off;
    autoindex off;

    keepalive_timeout  0;
    #keepalive_timeout  65;

    limit_conn_zone $binary_remote_addr zone=one:10m;
    perl_modules  perl;
    perl_require  download.pm;

    server {
        listen       182;
        server_name  example.com;
        proxy_set_header X-Real-IP $remote_addr;

        #charset koi8-r;

        location /nstatus {
            stub_status on;
            #allow 127.0.0.1;
            #deny all;
                        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /d/ {
            perl  download::handler;
        }

        # Free
        location /download_f/ {
            alias /example.com/uploads/;
            internal;
            set $limit_rate $arg_speed;
            limit_conn one 5;
        }

        # Registered
        location /download_r/ {
            alias /example.com/uploads/;
            internal;
            set $limit_rate $arg_speed;
            limit_conn one 5;
        }

        # Premium
        location /download_p/ {
            alias /example.com/uploads/;
            internal;
            set $limit_rate $arg_speed;
            limit_conn one 10;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

         server {
        listen       182;
        server_name  2.example.com;
        proxy_set_header X-Real-IP $remote_addr;

        #charset koi8-r;

        location /nstatus {
            stub_status on;
            #allow 127.0.0.1;
            #deny all;
                        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /d/ {
            perl  download::handler;
        }

        # Free
        location /download_f/ {
            alias /2.example.com/uploads/;
            internal;
            set $limit_rate $arg_speed;
            limit_conn one 5;
        }

        # Registered
        location /download_r/ {
            alias /2.example.com/uploads/;
            internal;
            set $limit_rate $arg_speed;
            limit_conn one 5;
        }

        # Premium
        location /download_p/ {
            alias /2.example.com/uploads/;
            internal;
            set $limit_rate $arg_speed;
            limit_conn one 10;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    }

}

My answer:


You’re missing a root directive in your server block. So I don’t expect your existing site to work without issues.

As for adding more sites, just create more server blocks.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.