我正在尝试为nginx配置两个域,每个域具有不同的ssl证书和不同的根位置。 以下代码两次显示完全相同的内容。 domain1.com应该转到/ home / ubuntu / web / html / domain1并应使用以下证书:/etc/letsencrypt/live/domain1.com/fullchain.pem证书。 domain2.com应该转到/ home / ubuntu / web / html / domain2并使用此/etc/letsencrypt/live/domain2.com/fullchain.pem证书。
我尝试了以下操作:
server {
listen 80;
server_name www.domain1.com;
return 301 https://domain1.com$request_uri;
}
server {
listen 80;
server_name domain1.com;
return 301 https://domain1.com$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
root /home/ubuntu/web/html/domain1;
index index.php index.html index.htm;
server_name domain1.com, www.domain1.com;
location / {
try_files $uri $uri/ $uri.html $uri.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param MAGE_MODE "developer";
}
}
server {
listen 80;
server_name www.domain2.com;
return 301 https://domain2.com$request_uri;
}
server {
listen 80;
server_name domain2.com;
return 301 https://domain2.com$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/letsencrypt/live/domain2.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain2.com/privkey.pem;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
root /home/ubuntu/web/html/domain2;
index index.php index.html index.htm;
server_name domain2.com, www.domain2.com;
location / {
try_files $uri $uri/ $uri.html $uri.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param MAGE_MODE "developer";
}
}
事实证明,总是选择一个服务器块作为默认服务器块,并且还将其用于另一个域。
也无法添加额外的默认服务器。