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現有的模塊:

查看nginx原有的模塊

1
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共存

1
2
3
4
5
6
7
8
9
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文件。

1
openssl rsa -in server.key -out server.key.unsecure

Nginx SSL性能調優

1
2
3
4
5
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;

這部分參考別家的文章:http://www.cnblogs.com/piscesLoveCc/p/6120875.html

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

8、nginx相關配置,看我的另一篇文章:配置nginx代理https

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章