(一)linux基于rhel7.0的Apache使用 | apache的安装 | 修改默认发布目录

查看网站所使用的网络服务器

[root@foundation156 ~]# curl -I www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Sun, 27 May 2018 14:53:00 GMT
Etag: "575e1f60-115"
Last-Modified: Mon, 13 Jun 2016 02:50:08 GMT
Pragma: no-cache
Server: bfe/1.0.8.18            <<<<<<

[root@foundation156 ~]# curl -I www.taobao.com
HTTP/1.1 302 Found
Server: Tengine                 <<<<<<
Date: Sun, 27 May 2018 14:53:50 GMT
Content-Type: text/html
Content-Length: 258
Connection: keep-alive
Location: https://www.taobao.com/
Set-Cookie: thw=cn; Path=/; Domain=.taobao.com; Expires=Mon, 27-May-19 14:53:50 GMT;
Strict-Transport-Security: max-age=31536000

!!!!!!SELINXU一定要关闭!!!!!!

一,安装apache

1,删除,为实验清空环境

[root@localhost ~]# rpm -e httpd php php-mysql
[root@localhost ~]# rm -rf /var/www/

2,安装httpd,启用服务,关闭防火墙

[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld

3,查看端口

[root@localhost ~]# netstat -antlupe | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      0          58228      4423/httpd

4,浏览器的默认发布目录/var/www/html,默认发布页面是index.html

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.html  <<<<<<注意:这个默认发布页面需要自己建立
[root@localhost html]# cat index.html 
hello world

5,浏览器访问ip


注意:在不修改配置文件的情况下,默认发布页面就是index.html,就是浏览器直接输入ip地址时,就可以直接看的页面,但是如果这个文件不存在,而是其他的比如test.html文件,浏览器是不会显示内容的(redhat会显示红帽的信息)

6,访问默认发布目录下面的其他页面

扫描二维码关注公众号,回复: 1712279 查看本文章
[root@localhost html]# ls
index.html
[root@localhost html]# vim test.html
[root@localhost html]# cat test.html 
test's pages

二,修改默认端口

1,修改主配置文件,重启服务

[root@localhost html]# vim /etc/httpd/conf/httpd.conf 
Listen 8080                                                     <<<<<<<<<42行
[root@localhost html]# systemctl restart httpd.service 
[root@localhost html]# netstat -antulpe | grep httpd            <<<<<<<<<查看端口,8080
tcp6       0      0 :::8080                 :::*                    LISTEN      0          65248      5551/httpd          

2,此时浏览器直接输入ip就访问不到了,其实浏览器里面的172.25.254.100=172.25.254.100:80,所以改为8080之后需要写全172.25.254.100:8080/test.html

3,改回80端口,重启服务

三,修改默认发布目录

[root@localhost ~]# mkdir /westos/html -p       >>>>>建立默认发布目录
[root@localhost ~]# cd /westos/html/
[root@localhost html]# vim index.html
[root@localhost html]# cat index.html            >>>>建立页面 
westos test
[root@localhost html]# vim /etc/httpd/conf/httpd.conf 
#DocumentRoot "/var/www/html"                    >>>>默认的注释掉
DocumentRoot "/westos/html"                      >>>>指定默认发布目录

<Directory "/westos/html">
        require all granted                      >>>>授权
</Directory>
[root@localhost html]# systemctl restart httpd.service 

修改默认发布页面

[root@localhost html]# pwd
/westos/html
[root@localhost html]# vim test.html                        <<<<<<<<<<<新建一个页面
[root@localhost html]# cat test.html 
nihao
[root@localhost html]# vim /etc/httpd/conf/httpd.conf 

#DocumentRoot "/var/www/html"
DocumentRoot "/westos/html"
<Directory "/westos">
        require all granted
        DirectoryIndex test.html                             <<<<<<<<<<<把新建的test.html设置为默认发布页面
</Directory>

[root@localhost html]# systemctl restart httpd.service 

注意:默认情况下,发布页面一定要命名为index.html,这是主配置文件决定的

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html                     <<<<<<<<<<<<指定了
</IfModule>


四,发布目录下面建立目录,确定该目录的默认发布目录

[root@localhost html]# mkdir linux                            <<<<<<<新建目录
[root@localhost html]# ls
index.html  linux  test.html
[root@localhost html]# cd linux/
[root@localhost linux]# vim index.html
[root@localhost linux]# cat index.html
linux index
[root@localhost linux]# vim test.html                          <<<<<<<建立两个页面
[root@localhost linux]# cat test.html
linux test
[root@localhost linux]# vim /etc/httpd/conf/httpd.conf 

加入改语句块
<Directory "/westos/html/linux">
        DirectoryIndex index.html                               <<<<<<<指定linux这个目录的默认发布页面为index.html
</Directory>

[root@localhost linux]# systemctl restart httpd.service








猜你喜欢

转载自blog.csdn.net/ha_weii/article/details/80473600
今日推荐