nginx配置域名(ssl和非ssl形式)的實現示例
概要
本文以阿里云為例,淺要介紹如何將域名指向你的服務器,以及如何配置ssl和非ssl的方式。
購買域名
購買域名不做描述,本文域名以helloword.com
為例
域名實名與備案
購買后,不實名和備案是無法使用的,這里不展開贅述
配置域名解析
域名解析就是將你的域名指向你的服務器:訪問域名+ip=訪問你的服務器+ip
注意:主機記錄可以在你的域名前拼接指定的域名前綴,比如hello.helloword.com
在阿里云控制臺依次點擊:域名控制臺
->域名列表
->操作:域名解析
,如下圖:
配置nginx(http)
首先不使用ssl證書,進行一個簡要的配置,此模式不支持使用https進行訪問:
登錄服務器,配置nginx.conf
文件嗎,在server塊進行如下配置:
server { listen 80; server_name hello.helloword.com; root html; index index.html index.htm; location / { proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } }
注意:監(jiān)聽的端口,也可配置成除443以外的其他端口,并且可重復配置,因為是通過域名訪問的。
訪問地址:端口如果是80則可省略:hello.helloword.com
配置nginx(ssl+https)
https需要使用ssl證書,首先申請一個ssl證書
申請并配置ssl證書
數字證書管理服務
->SSL證書
->免費證書->創(chuàng)建證書(如果沒有免費額度先購買下,免費的)
->證書申請
,如下圖:
然后點擊下一步,DNS驗證,然后提交審核即可,耐心等待通過后進行下一步
下載ssl證書
審核通過后,在SSL主頁面點擊下載,解壓后得到兩個證書文件,將這兩個文件放到服務器上,接下來進行nginx的配置
配置nginx
登錄服務器,配置nginx.conf
文件嗎,在server塊進行如下配置:
server { listen 80; listen 443 ssl; server_name hello.helloword.com; root html; index index.html index.htm; ssl_certificate /etc/nginx/cert/helloword/hello.helloword.com.pem; ssl_certificate_key /etc/nginx/cert/helloword/hello.helloword.com.key; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_session_timeout 5m; ssl_prefer_server_ciphers on; location / { proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } }
訪問地址:https://hello.helloword.com
到此這篇關于nginx配置域名(ssl和非ssl形式)的實現示例的文章就介紹到這了,更多相關nginx配置ssl和非ssl域名內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!