Nginx HTTP重定向HTTPS

現(xiàn)在什么蘋果、谷歌瀏覽器、小程序請求地扯都要求使用https了,如何把原來的http協(xié)議重定向到https中呢,這里大豬可以使用http反向代理軟件nginx

使用

安裝

yum install nginx -y

配置

cat /etc/nginx
server {
  listen   80;
  server_name dounine.com www.dounine.com;
  return     301 https://www.dounine.com$request_uri;
}
server {
  listen   443;
  server_name dounine.com dounine.com;
  return     301 https://www.dounine.com$request_uri;
}
server {
  listen   443;
  server_name www.dounine.com;
  ssl on;
  ssl_certificate /etc/nginx/dounine.crt;
  ssl_certificate_key /etc/nginx/dounine.key;

  location / {
    client_max_body_size    20m;
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header  Host  $host;
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
  }
}

以上配置可將 www.dounine.com、dounine.comhttps://dounine.com 重定向至 https://www.dounine.com 地扯中。

注意

記得將防火墻的80443端口允許。


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,692評論 19 139
  • Nginx是一個輕量級的,高性能的Web服務(wù)器以及反向代理和郵箱 (IMAP/POP3)代理服務(wù)器。它運(yùn)行在UNI...
    零一間閱讀 2,312評論 0 12
  • 轉(zhuǎn)載:https://help.aliyun.com/knowledge_detail/5974693.html?...
    meng_philip123閱讀 1,757評論 1 12
  • 宮廷鵝煲火鍋店! 傳奇中的火鍋,火鍋中的傳奇!《宮廷鵝煲》精選上等白鵝,新鮮果蔬,無任何添加,祖?zhèn)髅刂?,宮廷鵝煲先...
    鵝煲湯閱讀 658評論 0 1

友情鏈接更多精彩內(nèi)容