使用nginx搭建https服務器

丁丁的開發日記

一所懸命html

使用nginx搭建https服務器

最近在研究nginx,整好遇到一個需求就是但願服務器與客戶端之間傳輸內容是加密的,防止中間監聽泄露信息,可是去證書服務商那邊申請證書又不合算,由於訪問服務器的都是內部人士,因此本身給本身頒發證書,忽略掉瀏覽器的不信任警報便可。下面是頒發證書和配置過程。nginx

首先確保機器上安裝了openssl和openssl-devel瀏覽器

#yum install openssl
#yum install openssl-devel

而後就是本身頒發證書給本身緩存

#cd /usr/local/nginx/conf
#openssl genrsa -des3 -out server.key 1024
#openssl req -new -key server.key -out server.csr
#openssl rsa -in server.key -out server_nopwd.key
#openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt

至此證書已經生成完畢,下面就是配置nginx服務器

server {
    listen 443;
    ssl on;
    ssl_certificate  /usr/local/nginx/conf/server.crt;
    ssl_certificate_key  /usr/local/nginx/conf/server_nopwd.key;
}

而後重啓nginx便可。加密

ps: 若是出現「[emerg] 10464#0: unknown directive "ssl" in /usr/local/nginx-0.6.32/conf/nginx.conf:74」則說明沒有將ssl模塊編譯進nginx,在configure的時候加上「--with-http_ssl_module」便可^^spa

至此已經完成了https服務器搭建,但如何讓瀏覽器信任本身頒發的證書呢?server

今天終於研究搗鼓出來了,只要將以前生成的server.crt文件導入到系統的證書管理器就好了,具體方法:htm

控制面板 -> Internet選項 -> 內容 -> 發行者 -> 受信任的根證書頒發機構 -> 導入 -》選擇server.crtblog

 

 

清園

沉沒的Atlantis

Linux下安裝nginx

一.安裝依賴包

每次安裝軟件都必須,默認會少幾個包,必須安裝

yum install autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc

 

二.下載nginx和相關模塊

nginx:能夠去官網 http://nginx.org/ 下載最新版

wget http://nginx.org/download/nginx-1.7.8.tar.gz

 緩存模塊ngx_cache_purge:能夠去 http://labs.frickle.com/nginx_ngx_cache_purge/ 下載最新版本

wget http://labs.frickle.com/files/ngx_cache_purge-2.2.tar.gz
#解壓
tar zxvf nginx-1.7.8.tar.gz
tar zxvf ngx_cache_purge-2.2.tar.gz

 

三.編譯安裝 

按 Ctrl+C 複製代碼

./configure --prefix=/usr/local/nginx --with-http_ssl_module

make 

make install

按 Ctrl+C 複製代碼

安裝好以後,默認的nginx根目錄爲 /usr/local/nginx  

 

四.緩存配置例子

nginx配置的例子不少,就不贅述,直接問度娘吧.

相關文章
相關標籤/搜索