阿里雲Linux Ubentu 安裝 Nginx並配置https
下載nginx: wget http://nginx.org/download/nginx-1.8.0.tar.gz
下載openssl : wget http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz
下載zlib : wget http://www.zlib.net/fossils/zlib-1.2.8.tar.gz
下載pcre : wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
如果沒有安裝c++編譯環境,還得安裝,通過yum install gcc-c++完成安裝
下一步,編譯安裝
openssl :
[[email protected]] tar zxvf openssl-fips-2.0.9.tar.gz
[[email protected]] cd openssl-fips-2.0.9
[[email protected]] ./config && make && make install
[[email protected]] cd ..
pcre:
[[email protected]] tar zxvf pcre-8.38.tar.gz
[[email protected]] cd pcre-8.38
[[email protected]] ./configure && make && make install
[[email protected]] cd ..
zlib:
[[email protected]] tar zxvf zlib-1.2.8.tar.gz
[[email protected]] cd zlib-1.2.8
[[email protected]] ./configure && make && make install
[[email protected]] cd ..
最後安裝nginx
[[email protected]] tar zxvf nginx-1.8.0.tar.gz
[[email protected]] cd nginx-1.8.0
[[email protected]] ./configure && make && make install
啟動nginx
/usr/local/nginx/sbin/nginx
操作
啟動
/usr/local/nginx/sbin/nginx
重啟
/usr/local/nginx/sbin/nginx -s reload
停止
/usr/local/nginx/sbin/nginx -s stop
配置檔案路徑
/usr/local/nginx/conf/nginx.conf
出現錯誤提示
[[email protected] lib]# error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
原因 在RedHat 64位機器上nginx讀取的pcre檔案為/lib64/libpcre.so.1檔案,預設安裝pcre時libpcre.so檔案安裝在/usr/local/lib/目錄下,所以輸入/opt/nginx/sbin/nginx -V 找不到檔案路徑!!
1.首先確定安裝了pcre.
2.切換路徑: cd /usr/local/lib 執行 ln -s /usr/local/lib/libpcre.so.1 /lib64/
3.root許可權下新增軟連結 /usr/local/lib/libpcre.so.1 到 /lib64/ : ln -s /usr/local/lib/libpcre.so.1 /lib64/
配置https
nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:102
到解壓的nginx目錄下
./configure --with-http_ssl_module
當執行上面語句,出現./configure: error: SSL modules require the OpenSSL library.
更新源: apt-get update
sudo apt-get install openssl
sudo apt-get install libssl-dev
重新執行./configure --with-http_ssl_module
make ,切記不能make install 會覆蓋。
把原來nginx備份
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
把新的nginx覆蓋舊的
cp objs/nginx /usr/local/nginx/sbin/nginx
出現錯誤時cp: cannot create regular file ‘/usr/local/nginx/sbin/nginx’: Text file busy
用cp -rfp objs/nginx /usr/local/nginx/sbin/nginx解決
測試nginx是否正確
/usr/local/nginx/sbin/nginx -t
(nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful)
配置好ssl後一定要先停止再啟動,不能直接重啟命令
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx