nginx 中使用 meteor 的 ssl 和 https
ssl and https in nginx using meteor
我有这个 nginx 配置
server {
listen 80;
server_name app.com www.app.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
server_name app.com www.app.com;
ssl on;
ssl_certificate /etc/nginx/ssl/app.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location = /favicon.ico {
root /opt/myapp/app/programs/web.browser/app;
access_log off;
expires 1w;
}
location ~* "^/[a-z0-9]{40}\.(css|js)$" {
root /opt/myapp/app/programs/web.browser;
access_log off;
expires max;
}
location ~ "^/packages" {
root /opt/myapp/app/programs/web.browser;
access_log off;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
并使用正常设置的 mup 部署到 ec2
已部署,我可以访问该站点app.com
但是 https://app.com
不工作
as 在配置文件中,所有请求都被重写为 https
这里发生了什么
- 我输入app.com就可以访问该站点,这意味着它是
转发 app.com 广告 https://app.com
- 我无法访问 https://app.com 这意味着 nginx 不工作
以上两种情况哪个是正确的?
我别无选择。我检查了 ssl 检查器,他们显示未安装 ssl 证书。
那为什么我的应用在输入 app.com 时可以运行?
我对 NGINX 不是很了解,但查看我的工作生产配置,我发现有许多参数没有包含在您的配置中。
特别是您可能需要在顶部添加以下内容才能代理 websocket 连接:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
我的 443 服务器除了您已经拥有的之外,还包括以下内容:
server {
ssl_stapling on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
add_header Strict-Transport-Security "max-age=31536000;";
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
}
最后,我会尝试注释掉您的位置指令以进行错误检查。问题不应该出在您的 SSL 证书上,它应该仍然允许您访问(带有警告)自签名或配置错误的证书。希望这有帮助。
现在 Meteor Up 内置了 SSL Support。不用再辛苦了。
只需添加 SSL 证书和密钥并执行 mup setup
。
We use stud to terminate SSL
我有这个 nginx 配置
server {
listen 80;
server_name app.com www.app.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
server_name app.com www.app.com;
ssl on;
ssl_certificate /etc/nginx/ssl/app.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location = /favicon.ico {
root /opt/myapp/app/programs/web.browser/app;
access_log off;
expires 1w;
}
location ~* "^/[a-z0-9]{40}\.(css|js)$" {
root /opt/myapp/app/programs/web.browser;
access_log off;
expires max;
}
location ~ "^/packages" {
root /opt/myapp/app/programs/web.browser;
access_log off;
}
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
并使用正常设置的 mup 部署到 ec2
已部署,我可以访问该站点app.com
但是 https://app.com
不工作
as 在配置文件中,所有请求都被重写为 https
这里发生了什么
- 我输入app.com就可以访问该站点,这意味着它是 转发 app.com 广告 https://app.com
- 我无法访问 https://app.com 这意味着 nginx 不工作
以上两种情况哪个是正确的?
我别无选择。我检查了 ssl 检查器,他们显示未安装 ssl 证书。
那为什么我的应用在输入 app.com 时可以运行?
我对 NGINX 不是很了解,但查看我的工作生产配置,我发现有许多参数没有包含在您的配置中。
特别是您可能需要在顶部添加以下内容才能代理 websocket 连接:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
我的 443 服务器除了您已经拥有的之外,还包括以下内容:
server {
ssl_stapling on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
add_header Strict-Transport-Security "max-age=31536000;";
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
}
最后,我会尝试注释掉您的位置指令以进行错误检查。问题不应该出在您的 SSL 证书上,它应该仍然允许您访问(带有警告)自签名或配置错误的证书。希望这有帮助。
现在 Meteor Up 内置了 SSL Support。不用再辛苦了。
只需添加 SSL 证书和密钥并执行 mup setup
。
We use stud to terminate SSL