Centos6.5,安裝nginx,包含ssl模塊,如果已經安裝nginx則配置即可


使用https來訪問,一般都需要用域名來訪問(IP貌似也可以,我沒有深入研究),既然是域名,我比較常用的是實用nginx來做代理,一般來說安裝起來應該很簡單,但是還是遇到了一些有些非正常的、讓人覺得很蛋疼很sb的問題,在這里做一個記錄。

  安裝nginx(支持https,即開啟SSL模塊),需要首先安裝pcre、zlib、openssl;安裝openssl看我的另一篇文章:安裝openssl

  遇到的問題:我的電腦上本來已經有了zlib、openssl了,但是安裝nginx的時候還是報error,說找不到zlib和openssl。

zlib我就直接重新安裝了,但是openssl昨天剛剛重新安裝了1.1.0最新版本的,為什么還是會報找不到的錯誤呢?然后想了一下,會不會就是因為充裝了,所以路徑和nginx配置文件中openssl的路徑不一樣呢,所以我就使用yum重裝openssl,yum默認安裝的是openssl1.0.1版本的,太舊了,所以安裝好nginx以后,我又重新把openssl安裝了一遍,更新成最新的。下面說一下安裝nginx的步驟:

1、安裝jdk,系統默認的jdk版本不對,會造成后續很多問題,所以第一件事就是充裝jdk,自己去網上找jdk,然后傳到服務器上進行安裝,並配置環境變量。

2、安裝zlib,官網 http://zlib.net/ ,到上面下載個新版本,然后傳到服務器上進行安裝 (http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz?download)

[root@localhost]tar zxvf zlib-1.2.11.tar.gz
[root@localhost] cd zlib-1.2.11
[root@localhost]  ./configure && make && make install

3、安裝pcre,官網 https://sourceforge.net/projects/pcre/files/pcre/ ,到上面下載個新版本,然后傳到服務器進行安裝

[root@localhost] tar zxvf pcre-8.40.tar.gz
[root@localhost] cd pcre-8.40
[root@localhost]  ./configure && make && make install

4、安裝openssl,官網 https://www.openssl.org/source/ ,看我另一篇文章:安裝openssl

5、安裝nginx,官網 http://nginx.org/download/ ,到上面下載個新版本,然后傳到服務器進行安裝。

[root@localhost]tar zxvf nginx-1.8.0.tar.gz
[root@localhost] cd nginx-1.8.0

然后一步一步執行,如果報錯看的比較清楚:

首先執行 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

這里如果沒有安裝上面的pcre  zlib   openssl 會報錯,我遇到的比較蛋疼的是我已經安裝過了openssl最新版本,但還是報錯:


checking for OpenSSL library ... not found

checking for OpenSSL library in /usr/local/ ... not found

checking for OpenSSL library in /usr/pkg/ ... not found

checking for OpenSSL library in /opt/local/ ... not found


./configure: error: SSL modules require the OpenSSL library.

You can either do not enable the modules, or install the OpenSSL library

into the system, or build the OpenSSL library statically from the source

with nginx by using --with-openssl=<path> option.

看意思就是說找不到openssl庫,這就很郁悶了,明明我已經安裝過了,而且通過 openssl version指令可以看到我的openssl版本號;最后沒辦法了,只能按照上面的提示,在后面多一個配置項:--with-openssl=/home/softback/openssl-1.1.0e ,就執行通過了,我的完整的配置項是:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/home/softback/echo-nginx-module-0.60 --with-openssl=/home/softback/openssl-1.1.0e

配置好以后,執行 make && make install

一般configure命令執行通過,make和install都會很順利。

6、安裝好以后,啟動nginx

cd /usr/local/nginx/sbin/

./nginx

出現錯誤提示
[root@localhost lib]# error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
原因   在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/

然后再啟動就可以了。

7、~~萬一我們服務器上已經安裝過了nginx怎么辦呢?怎樣才能做到不重新安裝支持https呢?

解決方法:如果已經安裝了nginx,則只需要開啟SSL模塊即可。

 

首先查看nginx現有的模塊:

 

cd /usr/local/nginx/sbin/nginx
./nginx -V

 

在configure arguments:后面顯示的原有的configure參數如下:

1
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module

或者arguments:后面什么都沒有
那么就應該
切換到源碼包:

1
cd /usr/local/src/nginx-1.9.9   你的源碼放在那,就cd到那里。
我們的新配置信息就應該這樣寫:

1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_modul
運行上面的命令即可,等配置完

配置完成后,運行命令

1
make
這里不要進行make install,否則就是覆蓋安裝

然后備份原有已安裝好的nginx

1
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
然后將剛剛編譯好的nginx覆蓋掉原有的nginx(這個時候nginx要停止狀態)

1
cp ./objs/nginx /usr/local/nginx/sbin/
然后啟動nginx,仍可以通過命令查看模塊是否已經加入成功

1
/usr/local/nginx/sbin/nginx -V 

////////以下部分未做測試/////////

Nginx 配置Http和Https共存

server {
            listen 80 default backlog=2048;
            listen 443 ssl;
            server_name wosign.com;
            root /var/www/html;
  
            ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt;
            ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .Key;
        }
把ssl on;這行去掉,ssl寫在443端口后面。這樣http和https的鏈接都可以用

Nginx 配置SSL安全證書重啟避免輸入密碼
可以用私鑰來做這件事。生成一個解密的key文件,替代原來key文件。

openssl rsa -in server.key -out server.key.unsecure
Nginx SSL性能調優

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

////////以上部分未做測試/////////


免責聲明!

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



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