[root@localhost conf]# cd /etc/httpd/conf [root@localhost conf]# ls httpd.conf magic [root@localhost conf]# cp httpd.conf httpd.conf.bak
vi配置文件
开启行号
1 2 3 4 5 6 7
[root@localhost conf]# vi httpd.conf # # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. ... :set number
DocumentRoot "/data/web_data" # # Relax access to content within /var/www. # <Directory "/data/web_data"> AllowOverride None # Allow open access: Require all granted </Directory>
# Further relax access to the default document root: <Directory "/data/web_data"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information.
建立网站指向的文件夹
重启服务,报错,可以使用httpd来检测参数配置的错误,此处提示未建立文件夹
1 2 3 4 5 6 7 8
[root@localhost conf]# systemctl restart httpd Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details. [root@localhost conf]# httpd AH00526: Syntax error on line 119 of /etc/httpd/conf/httpd.conf: DocumentRoot '/data/web_data' is not a directory, or is not readable [root@localhost conf]# mkdir -p /data/web_data [root@localhost conf]# echo "Welcome to 2019 Computer Network Application contest" > /data/web_data/index.html [root@localhost conf]# systemctl restart httpd
[root@localhost conf]# service network restart Restarting network (via systemctl): [ OK ]
主机ping一下192.168.5.21,ping通继续
建立对应的网站文件
吸取到上次教训,先建文件再改配置。
1 2 3 4
[root@localhost conf]# mkdir -p /data/web_data/20 [root@localhost conf]# echo "this is the ip 20" > /data/web_data/20/index.html [root@localhost conf]# mkdir -p /data/web_data/21 [root@localhost conf]# echo "this is the ip 21" > /data/web_data/21/index.html
[root@localhost ~]# mkdir -p /data/web_data/20 [root@localhost ~]# echo "this is the port 6420" > /data/web_data/20/index.html [root@localhost ~]# mkdir -p /data/web_data/21 [root@localhost ~]# echo "this is the port 6421" > /data/web_data/21/index.html