获取存储在 Heroku 上的证书和密钥文件名,以便在 Nginx 服务器上设置 SSL
Get the certificate and key file names stored on Heroku to set up SSL on Nginx server
我想将证书和密钥添加到由 Heroku 提供和托管我的应用程序的 Nginx 服务器。这是我目前在我的 Nginx 配置文件中的内容。代理 SSL 服务器是否适用于此并保持服务器安全?如果不是,那么我应该如何获取我为特定应用程序上传到 Heroku 的 .pem
和 .key
文件的文件名?
nginx.conf.erb
daemon off;
#Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
events {
use epoll;
accept_mutex on;
worker_connections <%= ENV['NGINX_WORKER_CONNECTIONS'] || 1024 %>;
}
http {
server_tokens off;
log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
access_log <%= ENV['NGINX_ACCESS_LOG_PATH'] || 'logs/nginx/access.log' %> l2met;
error_log <%= ENV['NGINX_ERROR_LOG_PATH'] || 'logs/nginx/error.log' %>;
include mime.types;
default_type text/html;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#Must read the body in 65 seconds.
keepalive_timeout 65;
# handle SNI
proxy_ssl_server_name on;
upstream app_server {
server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
listen <%= ENV["PORT"] %>;
server_name _;
# Define the specified charset to the “Content-Type” response header field
charset utf-8;
location / {
proxy_ssl_name <%= ENV["HEROKU_DOMAIN"] %>;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
client_max_body_size 5M;
}
location /static {
alias /app/flask_app/static;
}
}
}
如果您从 CloudFlare 创建 SSL 证书,则无法通过 Heroku CLI 访问,但您可以通过 CloudFlare 下载。
- 请检查您是否通过 Configure-Cloudflare-and-Heroku-over-HTTPS.
路由您的域 Web
- 通过 CloudFlare 下载 SSL 证书。
- 为 Nginx 设置 SSL 证书 Setup SSL Cert。
希望对您有所帮助。
编辑
- 将 SSL 证书
.key
和 .pem
放入与 nginx.conf.erb
相同的文件夹中。 IE。 domain_name.key
& domain_name.pem
- 部署到 Heroku。
- 像这样使用配置:
ssl_certificate domain_name.pem;
ssl_certificate_key domain_name.key;
我想将证书和密钥添加到由 Heroku 提供和托管我的应用程序的 Nginx 服务器。这是我目前在我的 Nginx 配置文件中的内容。代理 SSL 服务器是否适用于此并保持服务器安全?如果不是,那么我应该如何获取我为特定应用程序上传到 Heroku 的 .pem
和 .key
文件的文件名?
nginx.conf.erb
daemon off;
#Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;
events {
use epoll;
accept_mutex on;
worker_connections <%= ENV['NGINX_WORKER_CONNECTIONS'] || 1024 %>;
}
http {
server_tokens off;
log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
access_log <%= ENV['NGINX_ACCESS_LOG_PATH'] || 'logs/nginx/access.log' %> l2met;
error_log <%= ENV['NGINX_ERROR_LOG_PATH'] || 'logs/nginx/error.log' %>;
include mime.types;
default_type text/html;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#Must read the body in 65 seconds.
keepalive_timeout 65;
# handle SNI
proxy_ssl_server_name on;
upstream app_server {
server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
listen <%= ENV["PORT"] %>;
server_name _;
# Define the specified charset to the “Content-Type” response header field
charset utf-8;
location / {
proxy_ssl_name <%= ENV["HEROKU_DOMAIN"] %>;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
client_max_body_size 5M;
}
location /static {
alias /app/flask_app/static;
}
}
}
如果您从 CloudFlare 创建 SSL 证书,则无法通过 Heroku CLI 访问,但您可以通过 CloudFlare 下载。
- 请检查您是否通过 Configure-Cloudflare-and-Heroku-over-HTTPS. 路由您的域 Web
- 通过 CloudFlare 下载 SSL 证书。
- 为 Nginx 设置 SSL 证书 Setup SSL Cert。
希望对您有所帮助。
编辑
- 将 SSL 证书
.key
和.pem
放入与nginx.conf.erb
相同的文件夹中。 IE。domain_name.key
&domain_name.pem
- 部署到 Heroku。
- 像这样使用配置:
ssl_certificate domain_name.pem;
ssl_certificate_key domain_name.key;