1. 程式人生 > 實用技巧 >centos 安裝 naginx服務以及配置 https

centos 安裝 naginx服務以及配置 https

一:下載 nginx

1.下載網址:https://nginx.org/en/download.html

找到穩定版 Stable Version ,如下

下載 nginx-1.18.0版本

2.上傳伺服器:/opt/nginxweb,並解壓 tar -zxvf xxxxxx

二: 進行安裝 (編譯,安裝)

1. 進入到nginx

2. 編譯前的處理,編譯和安裝

 // 這兩步是編輯前進行的,在這個步驟配置 ssl,也就是nginx可以使用nginx, 操作完後多了一個 makefile 的檔案
1031 ./configure 1032 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

// 編譯命令 1033 make
// 安裝 1034 make install

3。想要讓你的Nginx在任何位置上都能使用的話,我們就需要進入到cd /usr/local/bin中,在這進行軟連結:
ln -s /usr/local/nginx/sbin/nginx nginx  

4. 此時我執行 啟動nginx 命令 報錯

 1050  /usr/sbin/groupadd -f www
 1051  /usr/sbin/useradd -g www www

5. 啟動nginx ,進入到sbin 資料夾下,

./nginx 此時可以訪問nginx

6.配置https證書, 這裡記住目錄

  

 // 生成一個RSA金鑰
1038 mkdir -p /home/xda-deploy/ssl
1039 openssl genrsa -des3 -out server.key 2048
// 輸入密碼:

 // 生成一個證書請求  1040 openssl req -new -key server.key -out server.csr

//建立不需要輸入密碼的RSA證書,否則每次reload、restart都需要輸入密碼 1041 openssl rsa -in server.key -out server_nopass.key

//簽發證書(自己簽發) 1042 openssl x509 -req -days 36500 -in server.csr -signkey server.key -out server.crt

7.配置Nginx,

8.瀏覽器訪問

https://xxx.xxx.xx.xxx:443

443是https的預設埠,此時可以不需要填寫。

參考文件:1. https://blog.csdn.net/xu12387/article/details/86517817 2.https://www.cnblogs.com/boonya/p/7907999.html 3.https://blog.csdn.net/u012383839/article/details/72875210?utm_source=blogxgwz7

特別鳴謝: 同事提供的ssl 的字簽證書步驟