Есть главный домен site1.ru, а также несколько других (site2.ru, site3.ru ...). Необходимо все дополнительные домены перенаправить на основной с кодом 301. Как это правильно сделать?
Сейчас такие настройки:
s1.conf
# Ansible managed
# Additional website http
server {
listen 80 default_server;
server_name _;
access_log /var/log/nginx/default_access.log main;
error_log /var/log/nginx/default_error.log warn;
#charset utf-8;
server_name_in_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:80;
set $proxyserver "http://127.0.0.1:8888";
set $docroot "/var/www/html";
index index.php;
root "/var/www/html";
proxy_ignore_client_abort off;
#Redirect to ssl if need
#if (-f /var/www/html/.htsecure) { rewrite ^(.*)$ https://$host$1 permanent; }
if (-f /var/www/html/.htsecure) { rewrite ^(.*)$ https://site1.ru$1 permanent; }
# Include parameters common to all websites
include bx/conf/bitrix.conf;
# Include munin and nagios web
include bx/server_monitor.conf;
}
ssl.s1.conf
# Ansible managed
# Additional website http
server {
listen 443 default_server ssl http2;
server_name _;
include bx/conf/ssl.conf;
access_log /var/log/nginx/default_access.log main;
error_log /var/log/nginx/default_error.log warn;
#charset utf-8;
server_name_in_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:443;
proxy_set_header HTTPS YES;
proxy_set_header X-Forwarded-Proto https;
set $proxyserver "http://127.0.0.1:8888";
set $docroot "/home/bitrix/ext_www/default";
index index.php;
root "/home/bitrix/ext_www/default";
proxy_ignore_client_abort off;
# Include parameters common to all websites
include bx/conf/bitrix.conf;
# Include munin and nagios web
include bx/server_monitor.conf;
}