Ruby&Rails---给nginx添加https

我这里使用的是ubuntu的系统,给nginx添加https
之前rails项目配置nginx的文章在https://www.jianshu.com/p/c137b4e9987f

步骤1:申请ssl证书

我这边是通过腾讯云 https://cloud.tencent.com/product/ssl 申请,申请步骤里面有提供,申请后会下发证书。我们把它下载下来

Ruby&Rails---给nginx添加https_第1张图片
图片.png

步骤2: 把证书上传到你的服务器
scp 1_huangpeidong.xin_bundle.crt [email protected]:/home/hpd/hpdssl
scp 2_huangpeidong.xin.key [email protected]:/home/hpd/hpdssl
步骤3: 配置
sudo vi /etc/nginx/sites-enabled/your_pro_name.conf

编辑该文件


server {
  listen 80;
  server_name huangpeidong.xin www.huangpeidong.xin;

  root /your_pro_name/public;

  passenger_enabled on;

  passenger_min_instances 1;

  location ~ ^/assets/ {
    expires 1y;
    add_header Cache-Control public;
    add_header ETag "";
    break;
   }
}

server{
    listen 443;
    server_name huangpeidong.xin www.huangpeidong.xin;
    access_log /var/log/nginx/joke.log;
    ssl on;
    ssl_certificate /home/hpd/hpdssl/1_huangpeidong.xin_bundle.crt;
    ssl_certificate_key /home/hpd/hpdssl/2_huangpeidong.xin.key;
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_read_timeout 900;
    }
}
步骤4: 重启
sudo service nginx restart

然后查看去访问你的https的网址

你可能感兴趣的:(Ruby&Rails---给nginx添加https)