HTTP配置

HTTP配置

虚拟主机

虚拟主机有三类

相同IP不同端口

[root@localhost ~]# cd /etc/httpd/
[root@localhost httpd]# cd conf
[root@localhost conf]# vim httpd.conf
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80 将前面的#去掉
[root@localhost ~]# find / -name *vhosts.conf
/usr/share/doc/httpd/httpd-vhosts.conf
[root@localhost ~]# cp /usr/share/doc/httpd/httpd-vhosts.conf  /etc/httpd/conf.d/
[root@localhost ~]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# ls
autoindex.conf  httpd-vhosts.conf  README  userdir.conf  welcome.conf
[root@localhost conf.d]# vim httpd-vhosts.conf 


<VirtualHost *:80>
    DocumentRoot "/var/www/html/tanke"
    ServerName www.tanke1.com
    ErrorLog "/var/log/httpd/www.tanke1.com-error_log"
    CustomLog "/var/log/httpd/www.tanke1.com-access_log" common
</VirtualHost>
[root@localhost conf.d]# httpd -t
Syntax OK
[root@localhost conf.d]# systemctl  restart httpd

Alt text

[root@localhost conf.d]# vim httpd-vhosts.conf
Listen 81
<VirtualHost *:81>
    DocumentRoot "/var/www/html/feiji"
    ServerName www.feiji1.com
    ErrorLog "/var/log/httpd/www.feiji1.com-error_log"
    CustomLog "/var/log/httpd/www.feiji1.com-access_log" common
</VirtualHost>
[root@localhost conf.d]# httpd -t
Syntax OK
[root@localhost conf.d]# systemctl  restart httpd
[root@localhost conf.d]# ss -antl
State    Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN   0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN   0         128                      *:80                    *:*                
LISTEN   0         128                      *:81                    *:*                
LISTEN   0         128                   [::]:22                 [::]:*              

Alt text

不同IP相同端口

[root@localhost conf.d]# ip addr add 192.168.203.134/24 dev ens33
[root@localhost conf.d]# ip a
 inet 192.168.203.134/24 scope global secondary ens33

[root@localhost conf.d]# vim httpd-vhosts.conf 
<VirtualHost 192.168.203.133>
    DocumentRoot "/var/www/html/tanke"
    ServerName www.tanke1.com
    ErrorLog "/var/log/httpd/www.tanke1.com-error_log"
    CustomLog "/var/log/httpd/www.tanke1.com-access_log" common
</VirtualHost>


<VirtualHost 192.168.203.134>
    DocumentRoot "/var/www/html/feiji"
    ServerName www.feiji1.com
    ErrorLog "/var/log/httpd/www.feiji1.com-error_log"
    CustomLog "/var/log/httpd/www.feiji1.com-access_log" common
</VirtualHost>
[root@localhost conf.d]# httpd -t
Syntax OK
[root@localhost conf.d]# systemctl restart httpd

Alt text
Alt text

相同IP相同端口不同域名

[root@localhost conf.d]# vim httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/var/www/html/tanke"
    ServerName www.tanke1.com
    ErrorLog "/var/log/httpd/www.tanke1.com-error_log"
    CustomLog "/var/log/httpd/www.tanke1.com-access_log" common
</VirtualHost>


<VirtualHost *:80>
    DocumentRoot "/var/www/html/feiji"
    ServerName www.feiji1.com
    ErrorLog "/var/log/httpd/www.feiji1.com-error_log"
    CustomLog "/var/log/httpd/www.feiji1.com-access_log" common
</VirtualHost>
[root@localhost conf.d]# httpd -t
Syntax OK
[root@localhost conf.d]# systemctl  restart httpd

Linux修改hosts文件

[root@133 ~]# vim /etc/hosts
192.168.203.133 www.tanke1.com www.feiji1.com
[root@133 ~]# curl www.tanke1.com
<!DOCTYPE html>
<html lang="zh" class="no-js demo-1">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
		<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
		<script src="js/jquery.min.js"></script>
		<script src="js/Helper.js"></script>
		<script src="js/keyboard.js"></script>
		<script src="js/const.js"></script>
		<script src="js/level.js"></script>
		<script src="js/crackAnimation.js"></script>
		<script src="js/prop.js"></script>
		<script src="js/bullet.js"></script>
		<script src="js/tank.js"></script>
		<script src="js/num.js"></script>
		<script src="js/menu.js"></script>
		<script src="js/map.js"></script>
		<script src="js/Collision.js"></script>
		<script src="js/stage.js"></script>
		<script src="js/main.js"></script>
		<link rel="stylesheet" type="text/css" href="css/default.css" />
		<style type="text/css">
			#canvasDiv canvas{
				position:absolute;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<head><h3>操作说明:玩家1:wasd上左下右,space射击;玩家2:方向键,enter射击。n下一关,p上一关。</h3></head>
			<div class="main clearfix">
				<div id="canvasDiv" >
					<canvas id="wallCanvas" ></canvas> 
					<canvas id="tankCanvas" ></canvas>
					<canvas id="grassCanvas" ></canvas>
					<canvas id="overCanvas" ></canvas> 
					<canvas id="stageCanvas" ></canvas>
				</div>
			</div>
			
		</div><!-- /container -->
		<div style="text-align:center;">
<p>来源:<a href="http://www.mycodes.net/" target="_blank">源码之家</a></p>
</div>

	</body>

Windows修改hosts文件

  • Linux 或 MAC /etc/hosts
  • Windows C:\Windows\system32\drives\etc\hosts(一定要把 hosts 文件拖到桌面进行修改,修改完再拖回去)

Alt text

配置https

查询有没有ssl模块和其配置文件

[root@133 ~]# httpd  -M | grep ssl
[root@133 ~]# 

安装SSL

[root@133 ~]# yum install -y mod_ssl
[root@133 ~]# ls /etc/httpd/conf.modules.d/ |grep ssl
00-ssl.conf
[root@133 conf.modules.d]# cat 00-ssl.conf 
LoadModule ssl_module modules/mod_ssl.so
[root@133 conf.modules.d]# httpd -M |grep ssl
AH00526: Syntax error on line 85 of /etc/httpd/conf.d/ssl.conf:
SSLCertificateFile: file '/etc/pki/tls/certs/localhost.crt' does not exist or is empty

生成私有证书

[root@133 conf.modules.d]# mkdir -p /etc/pki/CA/
[root@133 conf.modules.d]# cd /etc/pki/CA/

CA生成一对密钥

[root@133 CA]# mkdir private
[root@133 CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.............+++++
.....+++++
e is 65537 (0x010001)
[root@133 CA]# cd private/
[root@133 private]# ls
cakey.pem

CA生成自签署证书

[root@133 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365
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) []:hb
Locality Name (eg, city) [Default City]:wh
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:www.tanke1.com
Email Address []:1@q.com
[root@133 CA]# ls
cacert.pem  private
[root@133 CA]# mkdir certs newcerts crl
[root@133 CA]# touch index.txt && echo 01 > serial

[root@133 CA]# cd /etc/httpd && mkdir ssl && cd ssl
[root@133 ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.............................+++++
.............................+++++
e is 65537 (0x010001)

客户端(例如httpd服务器)生成密钥

[root@133 CA]# cd /etc/httpd && mkdir ssl && cd ssl
[root@133 ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.............................+++++
.............................+++++
e is 65537 (0x010001)

客户端生成证书签署请求

[root@133 ssl]# openssl req -new -key httpd.key -days 365 -out httpd.csr
Ignoring -days; not generating a certificate
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) []:hb
Locality Name (eg, city) [Default City]:wh
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:www.tanke1.com
Email Address []:1@q.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

CA签署客户端提交上来的证书

[root@133 ssl]# openssl ca -in httpd.csr -out httpd.crt -days 365
Certificate is to be certified until Jul 21 14:36:27 2023 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
[root@133 ssl]# ls
httpd.crt  httpd.csr  httpd.key

[root@133 ssl]# cd /etc/httpd/conf.d/
[root@133 conf.d]# vim ssl.conf 

去掉#。更改域名
Alt text
更改crt在的位置,key在的位置
Alt text

[root@133 conf.d]# httpd -t
Syntax OK
[root@133 conf.d]# systemctl  restart httpd
[root@133 conf.d]# ss -antl
State    Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN   0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN   0         128                      *:80                    *:*                
LISTEN   0         128                   [::]:22                 [::]:*                
LISTEN   0         128                      *:443                   *:*          

Alt text

posted @ 2022-07-21 23:34  罗家龙  阅读(68)  评论(0编辑  收藏  举报