Answer the question
In order to leave comments, you need to log in
How to properly configure nginx for several (about 20) domains?
Good afternoon.
Prompt on a question.
There is a dedicated server with Nginx. Domains (there are 15 of them), I tied to the server as follows: in the registrar I registered the IP address of the server in the A-record (since my own DNS server was not configured). It turned out that now all sites are losing positions in promotion, because Yandex thinks that these domains are aliases for one of them.
What is the correct way to configure Nginx to serve multiple domains? Do I need to raise Apache (and will it help)? Or is it necessary to configure the DNS server?
Thank you.
Answer the question
In order to leave comments, you need to log in
We urgently need the current nginx configs to understand everything exactly.
General meaning
server {
server_name mysite1.ru;
...
}
server {
server_name mysite2.ru;
...
}
server {
server_name mysite3.ru;
...
}
server {
listen 80;
server_name www.site.ru;
rewrite ^ http://site.ru$request_uri?;
}
server {
listen 80;
server_name site.ru;
root /var/www/site.ru;
index index.php;
charset UTF-8;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/xml text/css application/x-javascript;
access_log /var/log/nginx/site.ru.access.log;
error_log /var/log/nginx/site.ru.error.log;
location /nginx_status {
stub_status on;
access_log off;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME /var/www/site.ru$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /var/www/site.ru;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ ^/(status|ping)$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
allow 127.0.0.1;
deny all;
}
}
I drive the hostname into a variable, just make folders with domain names in a certain shared directory, they are automatically picked up by nginx, and if you need apache, add a new domain - you just need to create a directory with it in /var/www/, everything else will be picked up automatically, hundreds of domains work fine, if you need slightly different settings for a specific one, we create a personal config for it, for everyone else it is common with variables, here are examples:
For nginx
server {
server_name ~^(?:www\.)?(?P<host_wo_www>.+)$;
server_name_in_redirect off;
resolver 127.0.0.1;
root /var/www/$host_wo_www;
access_log /var/log/nginx/$host_wo_www-access.log;
error_log /var/log/nginx/Allhost-error.log;
............
<VirtualHost *:8000>
UseCanonicalName Off
VirtualDocumentRoot "/var/www/%0"
ServerName "%0"
ServerAlias "*.%0"
ErrorLog ${APACHE_LOG_DIR}/AllHost-error.log
LogLevel error
#CustomLog ${APACHE_LOG_DIR}/%0-access.log combined
CustomLog /dev/null combined
<Directory "/var/www/%0/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
..............
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question