apache更改网站目录

目标:将默认网站修改成/home/wwwroot

1.修改配置文件

 

[root@lufoserver lufoserver]# 
[root@lufoserver lufoserver]# mkdir -p /home/wwwroot/
[root@lufoserver lufoserver]# echo "this new web directory" >> /home/wwwroot/index.html
[root@lufoserver lufoserver]# vim /etc/httpd/conf/httpd.conf 
...
# DocumentRoot: The directory out of which you will serve your
116 # documents. By default, all requests are taken from this directory, but
117 # symbolic links and aliases may be used to point to other locations.
118 #
119 DocumentRoot "/home/wwwroot"
120 
121 #
122 # Relax access to content within /var/www.
123 #
124 <Directory "/home/wwwroot">
125     AllowOverride None
126     # Allow open access:
127     Require all granted
128 </Directory>
129 
130 # Further relax access to the default document root:
131 <Directory "/var/www/html">

2.更改网站模块权限

更改文件目录的角色,保证selinux不会限制

[root@lufoserver lufoserver]# ls -Zd /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
[root@lufoserver lufoserver]# ls -Zd /home/wwwroot/
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/wwwroot/
[root@lufoserver lufoserver]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@lufoserver lufoserver]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/*
[root@lufoserver lufoserver]# ls -Zd /home/wwwroot/
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/wwwroot/
[root@lufoserver lufoserver]# restorecon -Rv /home/wwwroot/
restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
[root@lufoserver lufoserver]# ls -Zd /home/wwwroot/
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 /home/wwwroot/

3.重启httpd

重启,并后续开启自启动httpd

[root@lufoserver lufoserver]# systemctl restart httpd.service 
[root@lufoserver lufoserver]# systemctl enable httpd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

4.通过curl访问 

[root@lufoserver lufoserver]# curl -v localhost/index.html
* About to connect() to localhost port 80 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /index.html HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Fri, 04 Oct 2019 15:56:29 GMT
< Server: Apache/2.4.6 (CentOS)
< Last-Modified: Fri, 04 Oct 2019 15:42:59 GMT
< ETag: "17-594178e7e6cd8"
< Accept-Ranges: bytes
< Content-Length: 23
< Content-Type: text/html; charset=UTF-8
< 
this new web directory

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值