Nginx下升級https的方法步驟
購買證書
可以去阿里云的云盾證書服務購買
下載證書
在證書控制臺下載 Nginx 版本證書。下載到本地的壓縮文件包解壓后包含:
- .pem 文件:證書文件
- .key 文件:證書的私鑰文件(申請證書時如果沒有選擇 自動創(chuàng)建CSR ,則沒有該文件)
配置Nginx
1、在 Nginx 的安裝目錄下創(chuàng)建 cert 目錄,并且將下載的全部文件拷貝到 cert 目錄中,如果申請證書時是自己創(chuàng)建的CSR文件,請將對應的私鑰文件放到 cert 目錄下。
2、打開 Nginx 安裝目錄下 conf 目錄中的 nginx.conf 文件
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; #開啟gzip gzip_min_length 1k; #低于1kb的資源不壓縮 gzip_comp_level 3; #壓縮級別【1-9】,越大壓縮率越高,同時消耗cpu資源也越多,建議設置在4左右。 gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; #需要壓縮哪些響應類型的資源,多個空格隔開。不建議壓縮圖片,下面會講為什么。 gzip_disable "MSIE [1-6]\."; #配置禁用gzip條件,支持正則。此處表示ie6及以下不啟用gzip(因為ie低版本不支持) gzip_vary on; #是否添加“Vary: Accept-Encoding”響應頭 server { listen 80 default backlog=2048; #配置http可用 listen 443 ssl; #配置https server_name localhost; ssl_certificate ../cert/hzzly.pem; #配置證書文件 ssl_certificate_key ../cert/hzzly.key; #配置私鑰文件 ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root /home/hzzly; index index.html index.htm; } # location ^~ /apis/ { # proxy_set_header Host $host; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-Server $host; # # 匹配任何以 /apis/ 開始的請求,并停止匹配 其它location # proxy_pass http://xxxxxxxxxx/; # } # location ^~ /assets/ { # gzip_static on; # expires max; # add_header Cache-Control public; # } } }
3、重啟 Nginx
$ cd /usr/local/nginx/sbin $ ./nginx -s reload
錯誤詳解
1、Nginx如果未開啟SSL模塊,配置Https時提示錯誤
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in ...
Nginx開啟SSL模塊
切換到源碼包:
$ cd /usr/local/src/nginx-1.16.0
修改新的configure參數
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
配置完成后,運行命令
$ make //這里不要進行make install,否則就是覆蓋安裝
備份原有已安裝好的nginx
$ cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
將剛剛編譯好的nginx覆蓋掉原有的nginx
$ cp ./objs/nginx /usr/local/nginx/sbin/
重啟 Nginx
$ cd /usr/local/nginx/sbin $ ./nginx -s reload
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
基于nginx實現(xiàn)上游服務器動態(tài)自動上下線無需reload的實現(xiàn)方法
這篇文章主要介紹了基于nginx實現(xiàn)上游服務器動態(tài)自動上下線無需reload,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02Nginx訪問日志access_log配置及信息詳解(推薦)
當你設置日志級別成debug,如果你在調試一個在線的高流量網站的話,你的錯誤日志可能會記錄每個請求的很多消息,這樣會變得毫無意義,下面小編給大家介紹Nginx訪問日志access_log配置及信息詳解,感興趣的朋友跟隨小編一起看看吧2024-04-04在Nginx中配置image filter模塊來實現(xiàn)動態(tài)生成縮略圖
這篇文章主要介紹了在Nginx中配置image filter模塊來實現(xiàn)動態(tài)生成縮略圖的方法,包括縮略圖尺寸的設置等方面的介紹,需要的朋友可以參考下2015-12-12