【发布时间】:2020-02-11 22:25:09
【问题描述】:
我一直在尝试让我的应用程序在生产环境中运行。在我的config\environments\production.rb 中更改config.force_ssl = true 之前,我能够访问该站点。
我看到很多其他人有这个问题需要添加proxy_set_header X-Fowarded-Proto https;
我尝试在我的/etc/nginx/sites-available/default 中添加此内容,但没有发现任何区别。
我的完整default如下:
upstream puma {
server unix:///home/deploy/apps/appname/shared/tmp/sockets/appname-puma.sock;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl;
listen [::]:443 ssl;
root /var/www/html;
index index.html index.htm index.nginx-debian.html
server_name appname.com www.appname.com
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
}
进行更改后,我使用 sudo service nginx reload 重新加载了 nginx,然后是 sudo service nginx stop 和 sudo service nginx start
我错过了什么吗?
编辑:
我更新了我的default 并删除了config.force_ssl = true:
upstream puma {
server unix:///home/kiui/apps/appnamw/shared/tmp/sockets/appname-puma.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
keepalive_timeout 70;
server_name appname.com www.appname.com;
ssl on;
ssl_certificate /root/appname.com.chain.cer;
ssl_certificate_key /root/appname.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
root /home/deploy/apps/appname/current/public;
access_log /home/deploy/apps/appname/current/log/nginx.access.log;
error_log /home/deploy/apps/appname/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 10M;
}
我现在可以使用 http 但不能使用 https 访问该站点。
【问题讨论】:
-
我们是否正确假设您将
appname.com替换为您的实际域? -
是的,这是正确的。我想通了,会更新答案
标签: ruby-on-rails nginx