一盖呼、用戶驗證配置
1惜辑、修改配置文件
]# vim /usr/local/nginx/conf/nginx.conf
35 ????server {
?36 ????????listen ??????80;
?37 ????????server_name ?localhost;
?38 ????????auth_basic "xxx"; #認證用戶
?39 ????????auth_basic_user_file "/usr/local/nginx/pass"; #認證密碼
2、創(chuàng)建用戶
]# yum -y install httpd-tools
]# htpasswd? -c /usr/local/nginx/pass tom? ? ? #創(chuàng)建tom用戶? 注:第二次創(chuàng)建不用加-c
New password:
Re-type new password:
Adding password for user tom
3譬正、重啟驗證
]# /usr/local/nginx/sbin/nginx -s reload
驗證登錄網(wǎng)頁驗證
http://192.168.4.50/index.html
二宫补、虛擬主機
1卡者、創(chuàng)建虛擬主機
]# vim /usr/local/nginx/conf/nginx.conf
35? ? server {
36? ? ? ? listen? ? ? 80;
37? ? ? ? server_name? www.b.com;? #域名? 注:支持中文 (charset utf-8;)
38? ? ? ? # auth_basic "xxx";
39? ? ? ? # auth_basic_user_file "/usr/local/nginx/pass";
40? ? ? ? #charset koi8-r; 注:支持中文 (charset utf-8;)
41
42? ? ? ? #access_log? logs/host.access.log? main;
43
44? ? ? ? location / {
45? ? ? ? ? ? root? www ; #路徑
46? ? ? ? ? ? index? index.html index.htm;
47? ? ? ? }
2腰湾、驗證
~]# mkdir? /usr/local/nginx/www? #創(chuàng)建路徑
~]# echo? 11111? > /usr/local/nginx/www/index.html? #寫入內(nèi)容
~]# /usr/local/nginx/sbin/nginx -s reload
~]# curl http://www.b.com
三、ssl虛擬主機
1钓株、加密算法
l 對稱加密???(AES??DES) #適用單機
l 非對稱加密? ?(RSA??DSA) #適用網(wǎng)絡
]# cd /usr/local/nginx/conf/
]# openssl genrsa > cert.key? #生成私鑰
Generating RSA private key, 2048 bit long modulus
............................................................................................+++
..........+++
e is 65537 (0x10001)
]# openssl req -new -x509 -key cert.key > cert.pem? #生成證書
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]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:
2您单、配置
]# vim /usr/local/nginx/conf/nginx.conf
97? ? server {
98? ? ? ? listen? ? ? 443 ssl; #端口
99? ? ? ? server_name? www.c.com; #域名
100
101? ? ? ? ssl_certificate? ? ? cert.pem; #證書文件
102? ? ? ? ssl_certificate_key? cert.key; #私鑰文件
103
104? ? ? ? ssl_session_cache? ? shared:SSL:1m;
105? ? ? ? ssl_session_timeout? 5m; #超時時間
106
107? ? ? ? ssl_ciphers? HIGH:!aNULL:!MD5;
108? ? ? ? ssl_prefer_server_ciphers? on;
109
110? ? ? ? location / {
111? ? ? ? ? ? root? html;
112? ? ? ? ? ? index? index.html index.htm;
113? ? ? ? }
114? ? }
3斋荞、驗證
conf]# /usr/local/nginx/sbin/nginx? -s? reload
conf]# firefox? https://www.c.com
四、地址重寫
關于運維學習虐秦、分享平酿、交流,筆者開通了微信公眾號【大隆愛分享】悦陋,感興趣的朋友可以關注下蜈彼,歡迎加入,建立屬于我們自己的小圈子俺驶,一起學運維知識幸逆。
有需要技術交流的小伙伴可以加我微信棍辕,期待與大家共同成長,本人微信:可在公眾號獲取