L
L
littleguga2015-12-19 10:34:13
Nginx
littleguga, 2015-12-19 10:34:13

How to properly configure nginx for multiple sites and subdomains?

There are several sites: site.ru, site1.ru, site2.ru and subdomains: sub.site.ru, admin.sub.ru, mail.sub.ru, etc.
At the moment:
In the folder /sites-available/:
File site.ru :

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        server_name site.ru www.site.ru;
        root "/var/www/site.ru/";

        include sites-available/common.conf;
}

Site1.ru, site2.ru files are created with the following content:
server {
        server_name site.ru www.site.ru;
        root "/var/www/site.ru/";

        include sites-available/common.conf;
}
server {
        server_name blog.site.ru;
        root "/var/www/site.ru/blog/";

        include sites-available/common.conf;
}

common.conf:
index index.php index.html index.htm;
        ###
        location / {
                try_files $uri $uri/ =404;
        }
        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;
        }
        #Error log:
        error_log /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;

Is this approach correct? Or are there some misunderstandings?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gasoid, 2015-12-19
@littleguga

it is better to make a blog in a separate category and create a separate config file
blog.site.ru.conf

server {
        server_name blog.site.ru;
        root "/var/www/blog.site.ru/";

        include sites-available/common.conf;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question