1. 程式人生 > >Nginx下配置Https證書詳細過程

Nginx下配置Https證書詳細過程

一、Http與Https的區別

HTTP:是網際網路上應用最為廣泛的一種網路協議,是一個客戶端和伺服器端請求和應答的標準(TCP),用於從WWW伺服器傳輸超文字到本地瀏覽器的傳輸協議,它可以使瀏覽器更加高效,使網路傳輸減少。

HTTPS:是以安全為目標的HTTP通道,簡單講是HTTP的安全版,即HTTP下加入SSL層,HTTPS的安全基礎是SSL,因此加密的詳細內容就需要SSL。HTTPS協議的主要作用可以分為兩種:一種是建立一個資訊保安通道,來保證資料傳輸的安全;另一種就是確認網站的真實性。

HTTPS和HTTP的區別主要如下:

  • 1、https協議需要到ca申請證書,一般免費證書較少,因而需要一定費用。
  • 2、http是超文字傳輸協議,資訊是明文傳輸,https則是具有安全性的ssl加密傳輸協議。
  • 3、http和https使用的是完全不同的連線方式,用的埠也不一樣,前者是80,後者是443。
  • 4、http的連線很簡單,是無狀態的;HTTPS協議是由SSL+HTTP協議構建的可進行加密傳輸、身份認證的網路協議,比http協議安全。

二、使用openssl生成證書

openssl是目前最流行的SSL密碼庫工具,其提供了一個通用、健壯、功能完備的工具套件,用以支援SSL/TLS協議的實現。

比如生成到:/usr/local/ssl

openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /usr/local/ssl/nginx.key -out /usr/local/ssl/nginx.crt

生成過程:

# openssl req -x509 -nodes -days 36500 -newkey rsa:2048 -keyout /u    sr/local/ssl/nginx.key -out /usr/local/ssl/nginx.crt
Generating a 2048 bit RSA private key
...............................................................................+    ++
...............+++
writing new private key to '/usr/local/ssl/nginx.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:xxxx
Organizational Unit Name (eg, section) []:xxxx
Common Name (eg, your name or your server's hostname) []:xxxx(一般是域名)
Email Address []:
[email protected]
# ll total 8 -rw-r--r--. 1 root root 1391 Apr 21 13:29 nginx.crt -rw-r--r--. 1 root root 1704 Apr 21 13:29 nginx.key

三、Nginx安裝http_ssl_module模組

Nginx如果未開啟SSL模組,配置Https時提示錯誤。

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx

nginx缺少http_ssl_module模組,編譯安裝的時候帶上--with-http_ssl_module配置就行了。

本場景是伺服器已經安裝過nginx,但是未安裝http_ssl_module。

1.進入到原始碼包,如:

cd /app/download/nginx-1.12.2

2.configure:

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

3.make:

make

4.不需要執行make install,否則就覆蓋安裝了。

5.備份原有的nginx,如:

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak

6.然後將剛剛編譯好的nginx覆蓋掉原有的nginx(nginx需要停止)

cp ./objs/nginx /usr/local/nginx/sbin/

7.檢視安裝情況:

/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

四、nginx配置https

貼部分配置資訊:

    server {

        listen	80;
		server_name www.yourdomain.com;
	    rewrite ^(.*) https://$server_name$1 permanent; #http 跳轉 https
    }
server {
	listen 443 ssl;
	server_name www.yourdomain.com;
	ssl_certificate /usr/local/ssl/nginx.key;
	ssl_certificate_key /usr/local/ssl/nginx.crt;
	ssl_session_cache    shared:SSL:1m;
	ssl_session_timeout  5m;
	#禁止在header中出現伺服器版本,防止黑客利用版本漏洞攻擊
	server_tokens off;
	#如果是全站 HTTPS 並且不考慮 HTTP 的話,可以加入 HSTS 告訴你的瀏覽器本網站全站加密,並且強制用 HTTPS 訪問
	fastcgi_param   HTTPS               on;
	fastcgi_param   HTTP_SCHEME         https;
	access_log /usr/local/nginx/logs/httpsaccess.log;
}

先檢驗配置的對不對:

/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

重啟nginx:

/usr/local/nginx/sbin/nginx -s reload

訪問:





新手一枚,歡迎拍磚~ ~ ~

相關推薦

Nginx配置Https證書詳細過程

一、Http與Https的區別HTTP:是網際網路上應用最為廣泛的一種網路協議,是一個客戶端和伺服器端請求和應答的標準(TCP),用於從WWW伺服器傳輸超文字到本地瀏覽器的傳輸協議,它可以使瀏覽器更加高效,使網路傳輸減少。HTTPS:是以安全為目標的HTTP通道,簡單講是HT

linxu部署nginx的SSL證書HTTPS)依賴模組與使用nginx.conf配置https協議詳解

一:開始Nginx的SSL模組1.1 Nginx如果未開啟SSL模組,配置Https時提示錯誤1nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/n

Windows環境nginx在phpStudy配置https

nginx https phpstudy http Nginx配置文件內容如下#power by www.php.cn#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log

Linux nginx+tomcat配置https的總結和遇到的坑

master gcc apache ddr code style remote protocol lis 證書的獲取略 服務器的端口443確保外界網絡能夠進行訪問。 是否配置https: nginx:是 tomcat:否 1.首先查看nginx是否支持SSL。 參考鏈接:

使用Docker安裝的nginx配置HTTPS證書

新建ssl.conf,將檔案放入conf.d資料夾中 server { listen 443; server_name localhost; ssl on; root html; index index.ht

開發小程式 WAMP中Apache HTTPS證書詳細配置

由於微信小程式資料獲取url必須為https的路徑,因此需將伺服器部署為https,特此記錄期間踩過的坑。 環境:  - wampserver: 3.0.4_x64_apache2.4.18_mysql5.7.11_php5.6.19-7.0.4 - 系統: 阿里雲 window se

Nginx配置虛擬主機!詳細的那種!

1,先以root使用者登入。找到/usr/local/nginx (預設安裝到此處!) sbin :存放二進位制啟動檔案。往後每次進行配置變更後,都要來此處進行重啟生效。 HTML:存放網頁。有點了解應該都懂! 但是我們要在conf裡進行配置。哈哈 2,進入

weblogic配置https及匯入證書

在tomcat下及weblogic低版本配置https都需要產生金鑰庫檔案、產生證書請求檔案。。。匯入伺服器證書等一些步驟 因為我用的是weblogic 12c 自帶了演示標識金鑰庫DemoIdentity.jks和演示信任金鑰庫DemoTrust.jks,所以沒必要去生成

Nginx、tomcat配置https證書申請

證書的申請及Nginx和tomcat所需的檔案 近期部署公司主頁,要配置成https訪問,研究了下Nginx和tomcat配置https 所需的檔案及步驟,在這裡介紹從godaddy申請證書及配置的一系列操作 1.證書申請 Godaddy是一家提供域名註冊和網際網路

nginx配置https證書

因為最近我的ios司機們說要啟用https,不然應用要下架,直接一身冷汗出來了。 走了一些冤路,但最終結果是實現了,把相關的步聚記錄下來,希望對有需要的朋友有所幫助。 一、服務端生成金鑰 1、生成一個RSA金鑰 $ openssl genrsa

Nginx部署SSL證書並重定向至HTTPS

安裝包 進入 protoc .com .html permanent ... !null key 步驟一:下載 Nginx 版證書文件,解壓以後可以看到一個 .key 文件和 .crt/.pem 文件    步驟二:上傳證書。把上面的 .key 文件和 .crt/.pem

nginx配置了SSL,tomcat no SSL,專案使用https協議

https://feitianbenyue.iteye.com/blog/2056357   配置 Nginx 的轉

NGINX之——配置HTTPS加密反向代理訪問–自簽CA

left https rac lan -s tar 一個 eight fcm 轉載請註明出處:http://blog.csdn.net/l1028386804/article/details/46695495 出於公司內部訪問考慮,採用的CA是本機Openssl

Nginx+Tomcat配置https

dir source blank location prefix targe tps suffix session Nginx + Tomcat 配置 HTTPS 1、總述 瀏覽器和 Nginx 之間走的 HTTPS 通訊,而 Nginx 到 Tomcat 通過 proxy

Nginx 部署 HTTPS 與安全調優

quest tro efault attribute you attr inf [] validate 什麽是 HTTPS?# HTTPS(全稱:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全為目標的

(xampp)lampp 配置https(ssl)自簽雙向認證以後 apache無法啟動解決方案

art blog xtra 場景 問題 .com 客戶端瀏覽器 php https 自簽CA一般是沒有應用場景的,因為需要客戶端瀏覽器導入證書才能訪問 但是在某些需要內部使用的場景下,確實是一個解決方案 但是在lampp配置了雙向認證以後發現 原來自帶的管理命令 lampp

Nginx 配置Laravel 錯誤404

gin 分享 技術 log 圖片 pre nbsp bsp files 寶塔的訪問路徑改一下 在站點的配置文件下面server裏面加上 location / { try_files $uri $uri/ /index.php?$query_str

WAMP配置HTTPS+ZendGuardLoader

修改 nts level root com 路徑 ref pac rtu 公司的項目裏,有幾個文件是被加密的,經過一翻折騰,終於配置成功 文件加密技術用的是ZendGuard,所以必須安裝的PHP必須得是nts的 一、下載並配置PHP 先下載安裝php,註意VC版本和是

Mac配置Hadoop最詳細過程

pan alt agen mage 設置 apach 兩個 login class 一.準備工作: 1. JDK1.7版本及以上(貌似Hadoop只支持1.6以上的版本,不確定,保險起見用1.7,我自己用的是1.8) 2. 2.7.3版本的Hadoop https://

已經擁有開發者賬號的情況配置常用證書流程

自動安裝 調試 inf distrib 雙擊 logs 取證 蘋果 str 在上傳app到appStore前需要配置一些基本的證書,才能夠有權利在appStore發布程序。 1、開發者證書 開發者證書(分為開發和發布兩種,類型為iOSDevelopment,ios D