Rails passenger+nginx 部署生产环境,chrome 把 http 自动调成 https

SunA0 · February 25, 2021 · Last by SunA0 replied at March 02, 2021 · 585 hits

问题如题:

服务器上按照命令

rails s -b 192.168.8.43 -p 80 -d 

可以访问

按照教程

装了 passenger 通过 passenger 再装 nginx

nginx.conf

sbin/nginx -t

passenger start

看日志好像没什么问题?

lsof -i:80

ps -ef|grep nginx

结果就像开头的图片一样

而且不管哪个浏览器都会帮我自动跳到 https

可在以开发环境启动项目就不会跳转

在浏览器中,看看 HTTP Header 中的内容有啥不同?

@shiweifu 谢谢回复

开发环境 rails s rails s -b 192.168.8.43 -p 80 -d 

生产环境 passenger start

nginx location / 配置不对,不是你说的 https 的问题

server {
  listen 80;
  server_name 47.92.xxx.xxx;   # 用你自己的服务器 IP 位置

  root /root/rails_app/current/public;  # 用你自己的项目名称位置

  location {
     proxy_set_header Host $host;
  }
  passenger_enabled on;

  passenger_min_instances 1;
}

试试这个

我记得在 production env configuration 里,有一个默认的强制 HTTPS 的配置,把那个注释掉试试?(太久不搞 rails,很多细节记不清了)

检查 config/environments/production.rb 里面的 config.force_ssl 确保设置为 false

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
Reply to yfscret

不是 nginx.conf 问题,确实是 production.rb 没写好。谢谢你的回复

Reply to 317583395

还真是!😂

Reply to huacnlee

谢谢!确实是这个配置问题。看的时候也没注意到这块。感谢你的回复

SunA0 closed this topic. 03 Mar 10:15
You need to Sign in before reply, if you don't have an account, please Sign up first.