人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

Nginx下配置Https證書詳細(xì)過程

發(fā)布日期:2022-01-24 14:41 | 文章來源:腳本之家

一、Http與Https的區(qū)別

HTTP:是互聯(lián)網(wǎng)上應(yīng)用最為廣泛的一種網(wǎng)絡(luò)協(xié)議,是一個(gè)客戶端和服務(wù)器端請求和應(yīng)答的標(biāo)準(zhǔn)(TCP),用于從WWW服務(wù)器傳輸超文本到本地瀏覽器的傳輸協(xié)議,它可以使瀏覽器更加高效,使網(wǎng)絡(luò)傳輸減少。

HTTPS:是以安全為目標(biāo)的HTTP通道,簡單講是HTTP的安全版,即HTTP下加入SSL層,HTTPS的安全基礎(chǔ)是SSL,因此加密的詳細(xì)內(nèi)容就需要SSL。HTTPS協(xié)議的主要作用可以分為兩種:一種是建立一個(gè)信息安全通道,來保證數(shù)據(jù)傳輸?shù)陌踩?;另一種就是確認(rèn)網(wǎng)站的真實(shí)性。

HTTPS和HTTP的區(qū)別主要如下:

1、https協(xié)議需要到ca申請證書,一般免費(fèi)證書較少,因而需要一定費(fèi)用。

2、http是超文本傳輸協(xié)議,信息是明文傳輸,https則是具有安全性的ssl加密傳輸協(xié)議。

3、http和https使用的是完全不同的連接方式,用的端口也不一樣,前者是80,后者是443。

4、http的連接很簡單,是無狀態(tài)的;HTTPS協(xié)議是由SSL+HTTP協(xié)議構(gòu)建的可進(jìn)行加密傳輸、身份認(rèn)證的網(wǎng)絡(luò)協(xié)議,比http協(xié)議安全。

二、使用openssl生成證書

openssl是目前最流行的SSL密碼庫工具,其提供了一個(gè)通用、健壯、功能完備的工具套件,用以支持SSL/TLS協(xié)議的實(shí)現(xiàn)。

比如生成到:/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 []:xxxx@xxxx.com
# 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時(shí)提示錯(cuò)誤。

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

nginx缺少http_ssl_module模塊,編譯安裝的時(shí)候帶上--with-http_ssl_module配置就行了。

本場景是服務(wù)器已經(jīng)安裝過nginx,但是未安裝http_ssl_module。

1.進(jìn)入到源碼包,如:

cd /app/download/nginx-1.12.2

2.configure:

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#可能需要的依賴包
yum -y install pcre-devel openssl openssl-devel

3.make:

make

4.不需要執(zhí)行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 跳轉(zhuǎn) https
  }
server {
	listen 443 ssl;
	server_name www.yourdomain.com;
	ssl_certificate /usr/local/ssl/nginx.crt;
	ssl_certificate_key /usr/local/ssl/nginx.key;
	ssl_session_cache  shared:SSL:1m;
	ssl_session_timeout 5m;
	#禁止在header中出現(xiàn)服務(wù)器版本,防止黑客利用版本漏洞攻擊
	server_tokens off;
	#如果是全站 HTTPS 并且不考慮 HTTP 的話,可以加入 HSTS 告訴你的瀏覽器本網(wǎng)站全站加密,并且強(qiáng)制用 HTTPS 訪問
	fastcgi_param  HTTPS        on;
	fastcgi_param  HTTP_SCHEME     https;
	access_log /usr/local/nginx/logs/httpsaccess.log;
}

先檢驗(yàn)配置的對不對:

/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

訪問:

到此這篇關(guān)于Nginx下配置Https證書詳細(xì)過程的文章就介紹到這了,更多相關(guān)Nginx配置Https證書內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部