目标:将默认网站修改成/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