Vincent1
@Vincent1

Nginx по ошибке перенаправляет SSL на другой домен?

На сервере имеется несколько сайтов. A-examle.com работает на HTTPS, B-example.com работает по не защищенному протоколу HTTP.
Проблема в том, что если открыть в браузере httpS://B-example.com, то происходит 301 переадресация на httpS://A-examle.com. То же самое если открыть httpS://С-example.com, httpS://В-example.com (любые сайты на сервере которые работают по HTTP).
Т.е. не возникает ошибки, а просто срабатывает переадресация.
Настройки apache для B-example.com:
spoiler
<VirtualHost 89.222.88.23:8080>

    ServerName example.ru
    ServerAlias www.example.ru
    ServerAdmin info@example.ru
    DocumentRoot /home/example/web/example.ru/public_html
    ScriptAlias /cgi-bin/ /home/example/web/example.ru/cgi-bin/
    Alias /vstats/ /home/example/web/example.ru/stats/
    Alias /error/ /home/example/web/example.ru/document_errors/
    #SuexecUserGroup example example
    CustomLog /var/log/apache2/domains/example.ru.bytes bytes
    CustomLog /var/log/apache2/domains/example.ru.log combined
    ErrorLog /var/log/apache2/domains/example.ru.error.log
    <Directory /home/example/web/example.ru/public_html>
        AllowOverride All
        Options +Includes -Indexes +ExecCGI
        php_admin_value open_basedir /home/example/web/example.ru/public_html:/home/example/tmp
        php_admin_value upload_tmp_dir /home/example/tmp
        php_admin_value session.save_path /home/example/tmp
    </Directory>
    <Directory /home/example/web/example.ru/stats>
        AllowOverride All
    </Directory>

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid example example
        RGroups www-data
    </IfModule>
    <IfModule itk.c>
        AssignUserID example example
    </IfModule>

    IncludeOptional /home/example/conf/web/apache2.example.ru.conf*

</VirtualHost>

Настройки nginx для B-example.com:
spoiler
server {
    listen      89.222.88.23:80;
    server_name example.ru www.example.ru;
    error_log  /var/log/apache2/domains/example.ru.error.log error;

    location / {
        proxy_pass      http://89.222.88.23:8080;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
            root           /home/example/web/example.ru/public_html;
            access_log     /var/log/apache2/domains/example.ru.log combined;
            access_log     /var/log/apache2/domains/example.ru.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/example/web/example.ru/document_errors/;
    }

    location @fallback {
        proxy_pass      http://89.222.88.23:8080;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/example/conf/web/nginx.example.ru.conf*;
}


A-example.com:
apache
<VirtualHost 89.222.88.23:8443>

    ServerName A-example.ru
    ServerAlias www.A-example.ru
    ServerAdmin info@A-example.ru
    DocumentRoot /home/A-example/web/A-example.ru/public_html
    ScriptAlias /cgi-bin/ /home/A-example/web/A-example.ru/cgi-bin/
    Alias /vstats/ /home/A-example/web/A-example.ru/stats/
    Alias /error/ /home/A-example/web/A-example.ru/document_errors/
    #SuexecUserGroup A-example A-example
    CustomLog /var/log/apache2/domains/A-example.ru.bytes bytes
    CustomLog /var/log/apache2/domains/A-example.ru.log combined
    ErrorLog /var/log/apache2/domains/A-example.ru.error.log
    <Directory /home/A-example/web/A-example.ru/public_html>
        AllowOverride All
        SSLRequireSSL
        Options +Includes -Indexes +ExecCGI
        php_admin_value open_basedir /home/A-example/web/A-example.ru/public_html:/home/A-example/tmp
        php_admin_value upload_tmp_dir /home/A-example/tmp
        php_admin_value session.save_path /home/A-example/tmp
    </Directory>
    <Directory /home/A-example/web/A-example.ru/stats>
        AllowOverride All
    </Directory>
    SSLEngine on
    SSLVerifyClient none
    SSLCertificateFile /home/A-example/conf/web/ssl.A-example.ru.crt
    SSLCertificateKeyFile /home/A-example/conf/web/ssl.A-example.ru.key
    SSLCertificateChainFile /home/A-example/conf/web/ssl.A-example.ru.ca

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid A-example A-example
        RGroups www-data
    </IfModule>
    <IfModule itk.c>
        AssignUserID A-example A-example
    </IfModule>

    IncludeOptional /home/A-example/conf/web/sapache2.A-example.ru.conf*

</VirtualHost>

nginx
server {
    listen      89.222.88.23:443 http2;
    server_name A-example.ru www.A-example.ru;
    ssl         on;
    ssl_certificate      /home/A-example/conf/web/ssl.A-example.ru.pem;
    ssl_certificate_key  /home/A-example/conf/web/ssl.A-example.ru.key;
    error_log  /var/log/apache2/domains/A-example.ru.error.log error;

    location / {
        proxy_pass      https://89.222.88.23:8443;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
            root           /home/A-example/web/A-example.ru/public_html;
            access_log     /var/log/apache2/domains/A-example.ru.log combined;
            access_log     /var/log/apache2/domains/A-example.ru.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/A-example/web/A-example.ru/document_errors/;
    }

    location @fallback {
        proxy_pass      https://89.222.88.23:8443;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/A-example/conf/web/snginx.A-example.ru.conf*;
}



Сервер управляется VestaCP
  • Вопрос задан
  • 401 просмотр
Пригласить эксперта
Ответы на вопрос 2
@BorisKorobkov
Web developer
nginx.org/ru/docs/http/server_names.html
Если сервер является единственным сервером для слушающего порта, то nginx не будет проверять имена сервера вообще
Ответ написан
Комментировать
Так работает
nginx
server {
    listen 443 ssl;

    server_name shop.wildorchid.ru www.shop.wildorchid.ru;

  # enable SSL connection
 #include bx/conf/ssl.conf;
 ssl_certificate /etc/letsencrypt/live/shop.wildorchid.ru/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/shop.wildorchid.ru/privkey.pem;
 ssl on;
 keepalive_timeout 70;
 keepalive_requests 150;
 ssl_session_cache shared:SSL:10m;
 ssl_session_timeout 10m;
 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
  ssl_prefer_server_ciphers on;
 ssl_dhparam /etc/pki/nginx/dhparam.pem;
ssl_session_cache       shared:SSL:10m;
ssl_protocols  TLSv1.1 TLSv1.2;
  add_header Strict-Transport-Security "max-age=31536000;";
  #add_header Content-Security-Policy-Report-Only "default-src https:; script-src https: unsafe-eval unsafe-inline; style-src https: unsafe-inline; img-src https: data:; font-src https: data:; report-uri /csp-report";


  access_log /var/log/nginx/shop_access.log main;
  error_log  /var/log/nginx/shop_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:8887";

    set $imcontenttype  "text/html; charset=utf-8";
    set $docroot                "/home/bitrix/ext_www/shop.wildorchid.ru";

  index index.php;
  root "/home/bitrix/ext_www/shop.wildorchid.ru";

  # Include parameters common to all websites
  include bx/conf/bitrix.conf;

  # Include munin and nagios web
  include bx/server_monitor.conf;
}
apache2
<VirtualHost 127.0.0.1:8887>
    ServerName  shop.wildorchid.ru
        ServerAlias www.shop.wildorchid.ru      
        ServerAdmin webmaster@localhost
        DocumentRoot  /home/bitrix/ext_www/shop.wildorchid.ru

        ErrorLog logs/shop_error_log
        LogLevel warn
        CustomLog logs/shop_access_log combined

        <IfModule mod_rewrite.c>
                #Nginx should have "proxy_set_header HTTPS YES;" in location
                RewriteEngine On
                RewriteCond %{HTTP:HTTPS} =YES
                RewriteRule .* - [E=HTTPS:on,L]
        </IfModule>




        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

    
        <Directory /home/bitrix/ext_www/shop.wildorchid.ru>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                DirectoryIndex index.php index.html index.htm
                Order allow,deny
                allow from all
        php_admin_value session.save_path /tmp/php_sessions/ext_www/shop.wildorchid.ru
        php_admin_value upload_tmp_dir    /tmp/php_upload/ext_www/shop.wildorchid.ru
        </Directory>

    
</VirtualHost>

и еще чуть-чуть
<DirectoryMatch .*\.svn/.*>
                 Deny From All
        </DirectoryMatch>

        <DirectoryMatch .*\.git/.*>
                 Deny From All
        </DirectoryMatch>

        <DirectoryMatch .*\.hg/.*>
                 Deny From All
        </DirectoryMatch>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы