nginx配置https域名


                nginx安裝配置支持https和配置https域名

1 yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
1、安裝依賴
1 wget http://nginx.org/download/nginx-1.10.2.tar.gz
2 tar -zxvf  nginx-1.10.2.tar.gz
3 cd nginx-1.10.2/
2、下載nginx

3、配置nginx

  

./configure
 1 ./configure \
 2 --prefix=/usr/local/nginx \
 3 --conf-path=/usr/local/nginx/conf/nginx.conf \
 4 --pid-path=/usr/local/nginx/conf/nginx.pid \
 5 --lock-path=/var/lock/nginx.lock \
 6 --error-log-path=/var/log/nginx/error.log \
 7 --http-log-path=/var/log/nginx/access.log \
 8 --with-http_gzip_static_module \
 9 --http-client-body-temp-path=/var/temp/nginx/client \
10 --http-proxy-temp-path=/var/temp/nginx/proxy \
11 --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
12 --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
13 --http-scgi-temp-path=/var/temp/nginx/scgi
3.2、自定義配置
1 ./configure --prefix=/usr/local/nginx --with-http_ssl_module
3.3、支持HTTPS
make
1 /usr/local/nginx/sbin/nginx -V
查看nginx是否支持
1 ./configure --with-http_ssl_module
2 make
如果沒支持才編譯一下
 1 # 以下屬性中以ssl開頭的屬性代表與證書配置有關,其他屬性請根據自己的需要進行配置。
 2 server {
 3 listen 443 ssl;   #SSL協議訪問端口號為443。此處如未添加ssl,可能會造成Nginx無法啟動。
 4 server_name localhost;  #將localhost修改為您證書綁定的域名,例如:www.example.com。
 5 root html;
 6 index index.html index.htm;
 7 ssl_certificate cert/domain name.pem;   #將domain name.pem替換成您證書的文件名。
 8 ssl_certificate_key cert/domain name.key;   #將domain name.key替換成您證書的密鑰文件名。
 9 ssl_session_timeout 5m;
10 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  #使用此加密套件。
11 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   #使用該協議進行配置。
12 ssl_prefer_server_ciphers on;   
13 location / {
14 root html;   #站點目錄。
15 index index.html index.htm;   
16 }
17 }
按照下文中注釋內容修改nginx.conf文件:
1 server {
2  listen 80;
3  server_name localhost;   #將localhost修改為您證書綁定的域名,例如:www.example.com。
4 rewrite ^(.*)$ https://$host$1 permanent;   #將所有http請求通過rewrite重定向到https。
5  location / {
6 index index.html index.htm;
7 }
8 }
可選: 設置HTTP請求自動跳轉HTTPS。

本博文參考https://blog.csdn.net/long690276759/article/details/82790002和阿里雲官方文檔https://yundunnext.console.aliyun.com/?spm=5176.12818093.network-security.dbuy.488716d0rd77Sk&p=cas#/overview/cn-hangzhou 來寫出


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM