配置nginx代理实现https访问
配置nginx代理實現https訪問
Google宣布從Chrome網絡瀏覽器的下一個穩定版本(90)開始,將為地址欄中輸入的所有URL網址默認選擇HTTPS協議。這意味著未啟用HTTPS的網站的打開速度將受到影響。
對于尚不支持HTTPS的網站,當HTTPS嘗試失敗(包括名稱不匹配或不受信任的自簽名證書之類的證書錯誤,或DNS解析失敗的連接錯誤)時,Chrome會退回到HTTP。
一、nginx安裝
1、 下載安裝包
mkdir /opt/nginx cd /opt/nginx wget http://nginx.org/download/nginx-1.20.2.tar.gz wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz wget http://zlib.net/zlib-1.2.11.tar.gz wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz2、 安裝c++編譯環境
sudo yum install gcc-c++3、安裝perl(非必須,如果安裝OpenSSL時提示You need Perl 5,則需安裝)
tar -xzf perl-5.30.1.tar.gz cd perl-5.30.1 ./Configure -des -Dprefix=$HOME/localperl make make test make install4、 安裝OpenSSL
tar -zxvf openssl-fips-2.0.10.tar.gz cd openssl-fips-2.0.10/ ./config && make && make install5、 安裝pcre
tar -zxvf pcre-8.40.tar.gz cd pcre-8.40/ ./configure && make && make install yum -y install openssl openssl-devel6、 安裝zlib
tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11/ ./configure && make && make install7、 安裝nginx
tar -zxvf nginx-1.20.2.tar.gz cd nginx-1.20.2/ ./configure --with-http_ssl_module && make && make install8、 啟動nginx
[root@hhh nginx-1.20.2]# whereis nginx nginx: /usr/local/nginx [root@hhh nginx]# cd /usr/local/nginx/ [root@hhh nginx]# ls conf html logs sbin [root@hhh nginx]# /usr/local/nginx/sbin/nginx [root@hhh nginx]#9、 nginx基本操作
啟動 [root@localhost ~]# /usr/local/nginx/sbin/nginx 停止/重啟 [root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload) 命令幫助 [root@localhost ~]# /usr/local/nginx/sbin/nginx -h 驗證配置文件 [root@localhost ~]# /usr/local/nginx/sbin/nginx -t 配置文件 [root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf 查看nginx進程 [root@x86-103 nginx]# ps -aux | grep nginx root 2814713 0.0 0.0 32980 392 ? Ss 14:38 0:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 2814714 0.0 0.2 66588 4216 ? S 14:38 0:00 nginx: worker process root 2843725 0.0 0.0 12112 1112 pts/1 R+ 14:39 0:00 grep --color=auto nginx二、配置反向代理
編輯nginx.conf文件
文件中找到“HTTPS server”字樣,將下方注釋放開,按照如下配置,配置完成后重啟nginx。
三、獲取SSL證書
從阿里云獲取免費SSL證書
1、 購買域名(top域名首年1元)。
2、 購買完成域名后可0元購買一年ssl證書
3、 創建證書-證書申請
4、 配置域名解析dns
5、 驗證-提交審核
一般很快即可審核成功
6、 下載SSL證書文件
選擇NGINX進行下載,即可獲得pem和key文件
四、https訪問
一定要保證,證書申請時填寫的域名、dns配置的域名解析,以及本地nginx使用的證書文件一致,并且最終訪問時使用填寫的域名訪問,證書才有效,否則就會出現下面的情況(證書無效)。
總結
以上是生活随笔為你收集整理的配置nginx代理实现https访问的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Normal Libs For Java
- 下一篇: IP和MAC地址绑定的好处和作用