1. 程式人生 > >http服務搭建---ssl加密

http服務搭建---ssl加密

Web伺服器
瀏覽器:谷歌、火狐、IE、QQ瀏覽器.、百度瀏覽器、360瀏覽器、goole chrome、2345瀏覽器
伺服器 :html(寫網頁)超文字標記語言,
Jsp(java服務端網頁) php(伺服器程式語言) asp(動態伺服器語言)
解析和執行只能在伺服器上執行
Html與Jsp php asp區別:
1、 html是一切網頁語言的基礎
2、 Jsp php可以動態連結資料庫,但是最終都由伺服器解析成html
3、 Jsp php asp 文件都以html為基礎只是用程式程式碼動態輸出html程式碼,同一文件輸出不同的html程式碼,也是就是我們在瀏覽器看到的結果
4、 Jsp是一般瀏覽器都能編譯的
5、 Asp和php都需要伺服器的支援
6、 Jsp php asp都是動態網頁,當你訪問時,現在伺服器上執行,然後將執行後的網頁程式碼返回到電腦,你就能看到內容
7、 Html是靜態網頁的內容,不需要在伺服器端執行,直接傳送到你的電腦

先安裝httpd
Yum install –y httpd
Systemctl restart httpd
Systemctl status httpd
關閉防火牆
Systemctl stop firewalld
Setenforce 0
[[email protected] ~]# echo welcome to rhce > /var/www/html/index.html
[[email protected] html]# cat index.html
<h1>
welcome to rhce
<h1>
加粗加大
產看生成的檔案目錄
[

[email protected] html]# rpm -ql httpd
預設網路內容所在地 /var/www/html

AllowOverride引數就是指明Apache伺服器是否去找.htacess檔案作為配置檔案,如果設定為none,那麼伺服器將忽略.htacess檔案,如果設定為All,那麼所有在.htaccess檔案裡有的指令都將被重寫。對於AllowOverride,還可以對它指定如下一些能被重寫的指令型別
這裡寫圖片描述
主配置檔案是/etc/httpd/conf/httpd.conf。
配置儲存在的/etc/httpd/conf.d/目錄
[[email protected] ~]# cat /etc/httpd/conf.d/vhost.conf
<Directory “/www”>
allowoverride none
require all granted
</Directory>
<VirtualHost 172.16.50.37:80>
DocumentRoot “/www/80”
Servername 172.16.50.37
ErrorLog “/var/log/httpd/80-error_log”
CustomLog “/var/log/httpd/80-access_log” common
</VirtualHost>

虛擬主機(Virtual Host )是指在網路伺服器上分出一定的磁碟空間,使用者可以租用此部分空間,以供使用者放置站點及應用元件,提供必要的資料存放和傳輸功能, 虛擬主機,也叫“網站空間”,就是把一臺執行在網際網路上的物理伺服器劃分成多個“虛擬”伺服器

一、 基於ip多主機搭建
新增地址
[[email protected] ~]# nmcli connection modify ens33 +ipv4.addresses 172.16.50.38/24
[[email protected] ~]# nmcli connection modify ens33 ipv4.method manual
[[email protected] ~]# nmcli connection modify ens33 connection.autoconnect yes
[[email protected] ~]# nmcli connection up ens33
配置檔案
[[email protected] ~]# cat /etc/httpd/conf.d/vhost.conf
<Directory “/www”>
allowoverride none
require all granted
</Directory>
<VirtualHost 172.16.50.37:80>
DocumentRoot “/www/37”
Servername 172.16.50.37
ErrorLog “/var/log/httpd/37-error_log”
CustomLog “/var/log/httpd/37-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:80>
DocumentRoot “/www/38”
Servername 172.16.50.38
ErrorLog “/var/log/httpd/38-error_log”
CustomLog “/var/log/httpd/38-access_log” common
</VirtualHost>
[[email protected] ~]# mkdir /www/{37,38} –p
[[email protected] www]# echo welcom to 37 > /www/37/index.html
[[email protected] www]# echo welcom to 38 > /www/38/index.html
[[email protected] www]# systemctl restart httpd
二、基於多埠

[[email protected] conf.d]# mkdir /www/{8080,9080}
[[email protected] conf.d]# echo welcom to 8080 > /www/8080/index.html
[[email protected] conf.d]# echo welcom to 9080 > /www/9080/index.html
[[email protected] conf.d]# vi vhost.conf
<Directory “/www”>
allowoverride none
require all granted
</Directory>
<VirtualHost 172.16.50.37:80>
DocumentRoot “/www/37”
Servername 172.16.50.37
ErrorLog “/var/log/httpd/37-error_log”
CustomLog “/var/log/httpd/37-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:80>
DocumentRoot “/www/38”
Servername 172.16.50.38
ErrorLog “/var/log/httpd/38-error_log”
CustomLog “/var/log/httpd/38-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:8080>
DocumentRoot “/www/8080”
Servername 172.16.50.38
ErrorLog “/var/log/httpd/8080-error_log”
CustomLog “/var/log/httpd/8080-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:9080>
DocumentRoot “/www/9080”
Servername 172.16.50.38
ErrorLog “/var/log/httpd/9080-error_log”
CustomLog “/var/log/httpd/9080-access_log” common
</VirtualHost>
listen 8080
listen 9080
[[email protected] conf.d]# systemctl retart httpd
三、基於主機名(網址)
修改hosts檔案 C:\Windows\System32\drivers\etc
172.16.50.38 www.haha.com
172.16.50.38 www.xixi.com
[[email protected] conf.d]# vi vhost.conf
<Directory “/www”>
allowoverride none
require all granted
</Directory>
<VirtualHost 172.16.50.37:80>
DocumentRoot “/www/37”
Servername 172.16.50.37
ErrorLog “/var/log/httpd/37-error_log”
CustomLog “/var/log/httpd/37-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:80>
DocumentRoot “/www/38”
Servername 172.16.50.38
ErrorLog “/var/log/httpd/38-error_log”
CustomLog “/var/log/httpd/38-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:80>
DocumentRoot “/www/haha”
Servername www.haha.com
ErrorLog “/var/log/httpd/haha-error_log”
CustomLog “/var/log/httpd/haha-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:80>
DocumentRoot “/www/xixi”
Servername www.xixi.com
ErrorLog “/var/log/httpd/xixi-error_log”
CustomLog “/var/log/httpd/xix-access_log” common
</VirtualHost>
“vhost.conf” 28L, 816C
[[email protected] conf.d]# echo welcom to haha > /www/haha/index.html
[[email protected] conf.d]# echo welcom to xixi > /www/xixi/index.html
[[email protected] conf.d]# systemctl restart httpd
SSL:加密
[[email protected] conf.d]# cat vhost.conf
<Directory “/www”>
allowoverride none
require all granted
</Directory>
<VirtualHost 172.16.50.37:80>
DocumentRoot “/www/37”
Servername 172.16.50.37
ErrorLog “/var/log/httpd/37-error_log”
CustomLog “/var/log/httpd/37-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:80>
DocumentRoot “/www/38”
Servername 172.16.50.38
ErrorLog “/var/log/httpd/38-error_log”
CustomLog “/var/log/httpd/38-access_log” common
</VirtualHost>
<VirtualHost 172.16.50.38:443>
DocumentRoot “/www/haha”
Servername www.haha.com
ErrorLog “/var/log/httpd/haha-error_log”
CustomLog “/var/log/httpd/haha-access_log” common
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/haha.crt
SSLCertificateKeyFile /etc/pki/tls/certs/haha.key
</VirtualHost>
<VirtualHost 172.16.50.38:80>
DocumentRoot “/www/xixi”
Servername www.xixi.com
ErrorLog “/var/log/httpd/xixi-error_log”
CustomLog “/var/log/httpd/xix-access_log” common
</VirtualHost>
cd /etc/pki/tls/certs/
[[email protected] certs]# make haha.crt
umask 77 ; \
/usr/bin/openssl genrsa -aes128 2048 > haha.key
Generating RSA private key, 2048 bit long modulus
……………………+++
…….+++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key haha.key -x509 -days 365 -out haha.crt
Enter pass phrase for haha.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]:86
State or Province Name (full name) []:shaanxi
Locality Name (eg, city) [Default City]:xi’an
Organization Name (eg, company) [Default Company Ltd]:openalb
Organizational Unit Name (eg, section) []:ce
Common Name (eg, your name or your server’s hostname) []:cd
Email Address []:[email protected]

[[email protected] conf.d]# systemctl restart httpd
Enter SSL pass phrase for www.haha.com:443 (RSA) : **