Re: Ответ по имени и порту не указанному в server

Сергей Олегович shadow.tehb на gmail.com
Вс Апр 15 19:39:13 UTC 2018


Что в логах пишется?
fastcgi_pass у вас в обоих конфигах один, что отдаёт?

if'ы с rewrite лучше заменить отдельными server
root достаточно один раз задавать в секции server, дальше наследование
происходит

2018-04-15 20:51 GMT+03:00 Edward Gaba <nginx-forum на forum.nginx.org>:

> Доброго!
>
> Ситуация:
>
> nginx 1.12.2 (gentoo)
>
> На сервере (1 ip адрес) несколько доменов.
> конфиги каждого домена в своем файле, подключаются через include
> /etc/nginx/sites-enabled/*.conf;
> Для некоторых доменов настроен SSL, а другие без SSL.
>
> Суть в том, что все домены без SSL (слушают только порт 80, части конфига с
> SSL нет) отвечают на SSL порту, с сертификатом другого домена.
> Вот пример, domain1 отвечает на https и отображает контент domain2 с
> сертификатом domain2.
> Как это возможно и как исправить? Не могу понять, в чем ошибка.
>
> Полные 2 конфига:
>
> ########### DOMAIN1.RU ##########
>
>         server {
>                 listen 80;
>                 set $root_path '/var/www/sites/gaba/www/domain1.ru/www';
>                 set $root_php_chroot '/www/domain1.ru/www';
>                 root $root_path;
>                 server_name domain1.ru n.domain1.ru www.domain1.ru;
>
>                 if ($host = 'n.domain1.ru') {
>                     rewrite  ^/(.*)$  http://domain1.ru/$1  permanent;
>                 }
>
>                 if ($host = 'www.domain1.ru') {
>                     rewrite  ^/(.*)$  http://domain1.ru/$1  permanent;
>                 }
>
>                 access_log /var/www/sites/gaba/logs/domain1.ru_access.log;
>                 error_log /var/www/sites/gaba/logs/domain1.ru_error.log;
>
>                 index index.php index.html index.htm default.html
> default.htm;
>
>                 add_header X-Frame-Options "ALLOW-FROM: webvisor.com";
>
>                 location / {
>                         root $root_path;
>                         try_files $uri @dmrewrite;
>                 }
>
>                 location @dmrewrite {
>                         include /var/www/sites/gaba/www/domain
> 1.ru/www/rewrite.dat;
>                 }
>
>                 ##### Pagespeed config #####
>                 pagespeed LoadFromFile "http://domain1.ru/themes/dm/"
> "/var/www/sites/gaba/www/domain1.ru/www/themes/dm/";
>                 pagespeed LoadFromFile "http://domain1.ru/plugins/ratings/
> "
> "/var/www/sites/gaba/www/domain1.ru/www/plugins/ratings/";
>                 pagespeed LoadFromFile "http://domain1.ru/plugins/tags/"
> "/var/www/sites/gaba/www/domain1.ru/www/plugins/tags/";
>                 pagespeed LoadFromFile "http://domain1.ru/plugins/search/"
> "/var/www/sites/gaba/www/domain1.ru/www/plugins/search/";
>                 pagespeed LoadFromFile "http://domain1.ru/js/"
> "/var/www/sites/gaba/www/domain1.ru/www/js/";
>                 pagespeed LoadFromFile "http://domain1.ru/images/"
> "/var/www/sites/gaba/www/domain1.ru/www/images/";
>                 pagespeed LoadFromFileRuleMatch disallow \.*;
>                 pagespeed LoadFromFileRuleMatch allow
> \.(css|js|jpg|jpeg|png)$;
>                 location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+"
> {
>                     add_header "" "";
>                 }
>                 location ~ "^/ngx_pagespeed_static/" { }
>                 location ~ "^/ngx_pagespeed_beacon$" { }
>                 location /ngx_pagespeed_statistics { allow 127.0.0.1; deny
> all; }
>                 location /ngx_pagespeed_global_statistics { allow
> 127.0.0.1; deny all; }
>                 location /ngx_pagespeed_message { allow 127.0.0.1; deny
> all; }
>                 ##### Pagespeed config end #####
>
>                 location ~*
> ^.+\.(jpg|jpeg|gif|png|svg|swf|flv|js|ico|css|mp3|ogg|
> mpe?g|avi|zip|tgz|gz|bz2?|rar|doc|xls|rtf|pdf|exe|ppt|txt|
> tar|mid|midi|wav|html|htm)$
> {
>                 root $root_path;
>                 access_log off;
>                 expires 15d;
>                 }
>
>                 location ~ \.php$ {
>                 fastcgi_pass 127.0.0.1:9000;
>
>                 # set root path for php-fpm in chroot mode
>                 root $root_php_chroot;
>
>                 fastcgi_index index.php;
>                 include /etc/nginx/fastcgi_params;
>                 fastcgi_intercept_errors on;
>
>                 }
>
>                 location ~ \.(htpasswd|htaccess|tpl|dat|sqlite|svn|git)$ {
>                         deny all;
>                 }
>
>                 autoindex off;
>         }
>
> ########## DOMAIN2.RU ##############
>
>         server{
>                 listen 80;
>                 server_name www.domain2.ru domain2.ru;
>                 return 301 https://domain2.ru$request_uri;
>         }
>
>         server {
>                 listen 443 ssl http2;
>                 set $root_path '/var/www/sites/gaba/www/domain2.ru/www';
>                 set $root_php_chroot '/www/domain2.ru/www';
>                 root $root_path;
>                 server_name domain2.ru;
>
>                 if ($host = 'www.domain2.ru') {
>                     rewrite  ^/(.*)$  https://domain2.ru/$1  permanent;
>                 }
>
>                 ssl_certificate /etc/letsencrypt/live/domain2.
> ru/fullchain.pem;
>                 ssl_certificate_key /etc/letsencrypt/live/domain2.
> ru/privkey.pem;
>                 ssl_trusted_certificate /etc/letsencrypt/live/domain2.
> ru/chain.pem;
>
>                 resolver 127.0.0.1 8.8.8.8  valid=300s;
>                 resolver_timeout 5s;
>                 ssl_stapling on;
>                 ssl_stapling_verify on;
>                 ssl_session_timeout 5m;
>                 ssl_session_cache shared:SSL:10m;
>                 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
>                 ssl_prefer_server_ciphers on;
>                 ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:
> RSA+3DES:!NULL:!RC4;
>                 ssl_dhparam /etc/ssl/certs/dhparam.pem;
>                 add_header Strict-Transport-Security "max-age=31536000";
>
>                 access_log /var/www/sites/gaba/logs/domain2.ru_access.log;
>                 error_log /var/www/sites/gaba/logs/domain2.ru_error.log;
>
>                 index index.php index.html index.htm;
>
>                 add_header X-Frame-Options "ALLOW-FROM: webvisor.com";
>
>                 location / {
>                         root $root_path;
>                         try_files $uri @a2r;
>                 }
>
>                 location @a2r {
>                         include /var/www/sites/gaba/www/domain
> 2.ru/www/rewrite.dat;
>                 }
>
>                 location ~ /.well-known {
>                         allow all;
>                         root $root_path;
>                 }
>
>                 ##### Pagespeed config #####
>                 pagespeed LoadFromFile "https://domain2.ru/themes/a2r/"
> "/var/www/sites/gaba/www/domain2.ru/www/themes/a2r/";
>                 pagespeed LoadFromFile "https://domain2.ru/js/"
> "/var/www/sites/gaba/www/domain2.ru/www/js/";
>                 pagespeed LoadFromFile "https://domain2.ru/modules/
> fileAPI/css/"
> "/var/www/sites/gaba/www/domain2.ru/www/modules/fileAPI/css/";
>                 pagespeed LoadFromFileRuleMatch disallow \.*;
>                 pagespeed LoadFromFileRuleMatch allow \.(css|js)$;
>                 location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+"
> {
>                     add_header "" "";
>                 }
>                 location ~ "^/ngx_pagespeed_static/" { }
>                 location ~ "^/ngx_pagespeed_beacon$" { }
>                 location /ngx_pagespeed_statistics { allow 127.0.0.1; deny
> all; }
>                 location /ngx_pagespeed_global_statistics { allow
> 127.0.0.1; deny all; }
>                 location /ngx_pagespeed_message { allow 127.0.0.1; deny
> all; }
>                 ##### Pagespeed config end #####
>
>                 location ~*
> ^.+\.(jpg|jpeg|gif|png|svg|swf|flv|js|ico|css|mp3|ogg|
> mpe?g|avi|zip|tgz|gz|bz2?|rar|doc|xls|rtf|pdf|exe|ppt|txt|
> tar|mid|midi|wav|woff|woff2|html|htm)$
> {
>                 root $root_path;
>                 access_log off;
>                 expires 8d;
>                 }
>
>                 location ~ \.php$ {
>                 fastcgi_pass 127.0.0.1:9000;
>
>                 # set root path for php-fpm in chroot mode
>                 root $root_php_chroot;
>
>                 fastcgi_index index.php;
>                 include /etc/nginx/fastcgi_params;
>                 fastcgi_intercept_errors off;
>                 }
>
>                 location ~ \.(htpasswd|htaccess|tpl|dat|sqlite|svn|git)$ {
>                         deny all;
>                 }
>
>                 autoindex off;
>         }
>
> Posted at Nginx Forum: https://forum.nginx.org/read.
> php?21,279446,279446#msg-279446
>
> _______________________________________________
> nginx-ru mailing list
> nginx-ru на nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-ru
----------- следущая часть -----------
Вложение в формате HTML было извлечено…
URL: <http://mailman.nginx.org/pipermail/nginx-ru/attachments/20180415/bd0a4f67/attachment-0001.html>


Подробная информация о списке рассылки nginx-ru