我這里使用的是ubuntu的系統(tǒng),給nginx添加https
之前rails項(xiàng)目配置nginx的文章在http://www.reibang.com/p/c137b4e9987f
步驟1:申請(qǐng)ssl證書
我這邊是通過騰訊云 https://cloud.tencent.com/product/ssl 申請(qǐng)呼畸,申請(qǐng)步驟里面有提供痕支,申請(qǐng)后會(huì)下發(fā)證書。我們把它下載下來
步驟2: 把證書上傳到你的服務(wù)器
scp 1_huangpeidong.xin_bundle.crt hpd@120.77.45.76:/home/hpd/hpdssl
scp 2_huangpeidong.xin.key hpd@120.77.45.76:/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的網(wǎng)址