WEB服务器搭建-Apache

WEB服务器搭建-Apache

环境

hostnameipOS
server192.168.220.138centos7

WWW(World Wide Web万维网)服务器,主要功能是提供网上信息浏览服务

1、安装服务器端httpd

[root@server ~]# vim /etc/services
   89 http            80/tcp          www www-http    # WorldWideWeb HTTP
   90 http            80/udp          www www-http    # HyperText Transfer Protocol
   91 http            80/sctp                         # HyperText Transfer Protoco
  197 https           443/tcp                         # http protocol over TLS/SSL
  198 https           443/udp                         # http protocol over TLS/SSL
  199 https           443/sctp                        # http protocol over TLS/SSL
[root@server ~]# yum install httpd -y
[root@server ~]# systemctl start httpd
[root@server ~]# netstat -antup | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      1203/httpd
[root@server ~]# ls /etc/httpd/conf/httpd.conf 			#http配置文件
/etc/httpd/conf/httpd.conf
可以在web浏览器   http://ip  进行访问

2、部分配置说明

参数说明
ServerRoot “/etc/httpd”服务器根目录
Listen 80监听端口
ServerAdmin root@localhost管理员email
DocumentRoot “/var/www/html”网站存放位置
ServerName www.example.com:80服务器主机名
AddDefaultCharset UTF-8默认编码

3、LAMP

LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。

L—>Linux A—>Apache M—>Mysql P—>PHP

[root@server ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm ##下载mysql rpm包
[root@server ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm 
[root@server ~]# yum install httpd mysql-server php php-mysql -y
[root@server ~]# systemctl start mysql
[root@server ~]# cat /var/www/html/index.html 
***********</br>
*Welcome*</br>
***********
可以通过http://ip/index.html访问

4、访问控制

[root@server conf]# vim /etc/httpd/conf/httpd.conf
 <Directory "/var/www/html">
132     #
133     # Possible values for the Options directive are "None", "All",
134     # or any combination of:
135     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
136     #
137     # Note that "MultiViews" must be named *explicitly* --- "Options All"
138     # doesn't give it to you.
139     #
140     # The Options directive is both complicated and important.  Please see
141     # http://httpd.apache.org/docs/2.4/mod/core.html#options
142     # for more information.
143     #
144     Options Indexes FollowSymLinks
145 
146     #
147     # AllowOverride controls what directives may be placed in .htaccess files.
148     # It can be "All", "None", or any combination of the keywords:
149     #   Options FileInfo AuthConfig Limit
150     #
151     AllowOverride None
152 
153     #
154     # Controls who can get stuff from this server.
155     #
156     Require all granted
157     Deny from 192.168.220.0/24		#拒绝这个网段访问
158 </Directory>

[root@server conf]# curl 192.168.220.138/index.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /index.html
on this server.</p>
</body></html>

5、通过别名访问其他目录内容

[root@server ~]# touch /usr/local/test.html
[root@server ~]# vim !$
vim /usr/local/test.html
Welcome
[root@server ~]# vim /etc/httpd/conf/httpd.conf 
353 Alias /test/ "/usr/local/"
354 <Directory "/usr/local/">
355		Options Indexes FollowSymLinks			#Indexes表示展示目录下内容。FollowSymLinks允许软链接。前边加“-”表示取消这个功能。
356     AllowOverride none
357     Require all granted
358 </Directory>
可以通过 http://ip/test/test.html访问。/usr/local/下的网站。

6、通过软连接访问其他目录内容

[root@server ~]# ln -s /usr/local/ /var/www/html/test
[root@server ~]# ll !$
ll /var/www/html/test
lrwxrwxrwx 1 root root 11 7月  24 13:59 /var/www/html/test -> /usr/local/
将5中的配置注释掉进行测试
[root@server ~]# systemctl restart httpd
可以通过 http://ip/test访问。/usr/local/下的目录文件。 

7、虚拟主机

====================基于IP(用的不多)=============================
[root@server ~]# ifconfig eno16777736:1 192.168.220.140	#给网卡加一个额外ip  ifconfig  网卡名:1  IP
[root@server html]# mkdir /var/www/html/test
[root@server ~]# vim /etc/httpd/conf/httpd.conf
363 <VirtualHost 192.168.220.138:80>
364 DocumentRoot /var/www/html/
365 </VirtualHost>
366 <VirtualHost 192.168.220.140:80>
367 DocumentRoot /var/www/html/test/
368 </VirtualHost>
[root@server ~]# echo "111" > /var/www/html/test/index.html
[root@server ~]# systemctl restart httpd
通过ip就可访问
=========================基于域名===================================
[root@server ~]# vim /etc/httpd/conf/httpd.conf
363 <VirtualHost *:80>
364 DocumentRoot /var/www/html/
365 ServerName www.example.com
366 </VirtualHost>
367 <VirtualHost *:80>
368 DocumentRoot /var/www/html/test/
369 ServerName test.example.com
370 </VirtualHost>
[root@server ~]# systemctl restart httpd
[root@server ~]# vim /etc/hosts
192.168.220.138 server www.example.com  test.example.com
[root@server ~]# curl test.example.com		#curl命令测试
111
=========================基于端口===================================
[root@server ~]# vim /etc/httpd/conf/httpd.conf
43 Listen 6111
44 Listen 6222
364 <VirtualHost *:6111>
365 DocumentRoot /var/www/html/
366 ServerName www.example.com
367 </VirtualHost>
368 <VirtualHost *:6222>
369 DocumentRoot /var/www/html/test/
370 ServerName test.example.com
371 </VirtualHost>
[root@server ~]# systemctl restart httpd
[root@server ~]# curl  -h | grep port
-P, --ftp-port ADR  Use PORT with given address instead of PASV (F)
    --local-port RANGE  Force use of these local port numbers
-x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port
    --proxy1.0 HOST[:PORT]  Use HTTP/1.0 proxy on given port
    --socks4 HOST[:PORT]  SOCKS4 proxy on given host + port
    --socks4a HOST[:PORT]  SOCKS4a proxy on given host + port
    --socks5 HOST[:PORT]  SOCKS5 proxy on given host + port
[root@server ~]# curl http://192.168.220.138:6222
111
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值