nginx - NGINX 多个 SSL 证书,具有一个 ip、不同的根和域
问题描述
我正在尝试使用两个域配置 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";
}
}
事实证明,始终选择一个服务器块作为默认值,并且也用于另一个域。
添加额外的默认服务器也不起作用。
解决方案
推荐阅读
- exception - 当硬故障处理程序不可用或禁用时,我们会得到连续的硬故障吗?
- java - 我找不到 if 语句使用哪个变量
- python - 计算数据集中所有电影的平均预算
- linux - 与 localhost 的连接是通过内存还是磁盘复制的?
- pptp - DD WRT 路由器上的 PPTP 客户端
- swift - 即使文件存在且可访问,也无法播放音频 URL
- python - UrlLib 提供 HTTP 404
- java - Java谓词如何
允许没有参数的方法? - firebase - 尝试使用 Flutter 和 Firebase 复制 Netflix UI 时出现“RangeError (index)”
- html - Nodemailer 没有找到任何图像,但找到了文本