1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41mkdir -p /media/cdrom mount /dev/cdrom /media/cdrom mount: /dev/sr0 is write-protected, mounting read-only vim /etc/yum.repos.d/rhel7.repo [rhel7] name=rhel7 baseurl=file:///media/cdrom enabled=1 gpgcheck=0 yum install httpd Loaded plugins: langpacks, product-id, subscription-manager ………………省略部分输出信息……………… Dependencies Resolved =============================================================================== Package Arch Version Repository Size =============================================================================== Installing: httpd x86_64 2.4.6-17.el7 rhel 1.2 M Installing for dependencies: apr x86_64 1.4.8-3.el7 rhel 103 k apr-util x86_64 1.5.2-6.el7 rhel 92 k httpd-tools x86_64 2.4.6-17.el7 rhel 77 k mailcap noarch 2.1.41-2.el7 rhel 31 k Transaction Summary =============================================================================== Install 1 Package (+4 Dependent packages) Total download size: 1.5 M Installed size: 4.3 M Is this ok [y/d/N]: y Downloading packages: ………………省略部分输出信息……………… Complete! systemctl start httpd systemctl enable httpd ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user. target.wants/httpd.service' firefox
配置文件的名称 | 存放位置 |
---|---|
服务目录 | /etc/httpd |
主配置文件 | /etc/httpd/conf/httpd.conf |
网站数据目录 | /var/www/html |
访问日志 | /var/log/httpd/access_log |
错误日志 | /var/log/httpd/error_log |
注释行信息、全局配置、区域配置
参数 | 用途 |
---|---|
ServerRoot | 服务目录 |
ServerAdmin | 管理员邮箱 |
User | 运行服务的用户 |
Group | 运行服务的用户组 |
ServerName | 网站服务器的域名 |
DocumentRoot | 网站数据目录 |
Directory | 网站数据目录的权限 |
Listen | 监听的IP地址与端口号 |
DirectoryIndex | 默认的索引页页面 |
ErrorLog | 错误日志文件 |
CustomLog | 访问日志文件 |
Timeout | 网页超时时间,默认为300秒 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28echo "Welcome To LinuxProbe.Com" > /var/www/html/index.html firefox mkdir /home/wwwroot echo "The New Web Directory" > /home/wwwroot/index.html vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息……………… 113 114 # 115 # 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> ………………省略部分输出信息……………… systemctl restart httpd firefox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115vim /etc/httpd/conf.d/userdir.conf 1 # 2 # UserDir: The name of the directory that is appended onto a user's home 3 # directory if a ~user request is received. 4 # 5 # The path to the end user account 'public_html' directory must be 6 # accessible to the webserver userid. This usually means that ~userid 7 # must have permissions of 711, ~userid/public_html must have permissions 8 # of 755, and documents contained therein must be world-readable. 9 # Otherwise, the client will only receive a "403 Forbidden" message. 10 # 11 <IfModule mod_userdir.c> 12 # 13 # UserDir is disabled by default since it can confirm the presence 14 # of a username on the system (depending on home directory 15 # permissions). 16 # 17 # UserDir disabled 18 19 # 20 # To enable requests to /~user/ to serve the user's public_html 21 # directory, remove the "UserDir disabled" line above, and uncomment 22 # the following line instead: 23 # 24 UserDir public_html 25 </IfModule> 26 27 # 28 # Control access to UserDir directories. The following is an example 29 # for a site where these directories are restricted to read-only. 30 # 31 <Directory "/home/*/public_html"> 32 AllowOverride FileInfo AuthConfig Limit Indexes 33 Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec 34 Require method GET POST OPTIONS 35 </Directory> su - linuxprobe Last login: Fri May 22 13:17:37 CST 2017 on :0 mkdir public_html echo "This is linuxprobe's website" > public_html/ index.html chmod -Rf 755 /home/linuxprobe #127.0.0.1/~linuxprobe getsebool -a | grep http httpd_anon_write --> off httpd_builtin_scripting --> on httpd_can_check_spam --> off httpd_can_connect_ftp --> off httpd_can_connect_ldap --> off httpd_can_connect_mythtv --> off httpd_can_connect_zabbix --> off httpd_can_network_connect --> off httpd_can_network_connect_cobbler --> off httpd_can_network_connect_db --> off httpd_can_network_memcache --> off httpd_can_network_relay --> off httpd_can_sendmail --> off httpd_dbus_avahi --> off httpd_dbus_sssd --> off httpd_dontaudit_search_dirs --> off httpd_enable_cgi --> on httpd_enable_ftp_server --> off httpd_enable_homedirs --> off httpd_execmem --> off httpd_graceful_shutdown --> on httpd_manage_ipa --> off httpd_mod_auth_ntlm_winbind --> off httpd_mod_auth_pam --> off httpd_read_user_content --> off httpd_run_stickshift --> off httpd_serve_cobbler_files --> off httpd_setrlimit --> off httpd_ssi_exec --> off httpd_sys_script_anon_write --> off httpd_tmp_exec --> off httpd_tty_comm --> off httpd_unified --> off httpd_use_cifs --> off httpd_use_fusefs --> off httpd_use_gpg --> off httpd_use_nfs --> off httpd_use_openstack --> off httpd_use_sasl --> off httpd_verify_dns --> off named_tcp_bind_http_port --> off prosody_bind_http_port --> off #-P 永久生效 setsebool -P httpd_enable_homedirs=on firefox htpasswd -c /etc/httpd/passwd linuxprobe New password:此处输入用于网页验证的密码 Re-type new password:再输入一遍进行确认 Adding password for user linuxprobe vim /etc/httpd/conf.d/userdir.conf 27 # 28 # Control access to UserDir directories. The following is an example 29 # for a site where these directories are restricted to read-only. 30 # 31 <Directory "/home/*/public_html"> 32 AllowOverride all #刚刚生成出来的密码验证文件保存路径 33 authuserfile "/etc/httpd/passwd" #当用户尝试访问个人用户网站时的提示信息 34 authname "My privately website" 35 authtype basic #用户进行账户密码登录时需要验证的用户名称 36 require user linuxprobe 37 </Directory> systemctl restart httpd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61mkdir -p /home/wwwroot/10 mkdir -p /home/wwwroot/20 mkdir -p /home/wwwroot/30 echo "IP:192.168.10.10" > /home/wwwroot/10/index.html echo "IP:192.168.10.20" > /home/wwwroot/20/index.html echo "IP:192.168.10.30" > /home/wwwroot/30/index.html vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息……………… 113 <VirtualHost 192.168.10.10> 114 DocumentRoot /home/wwwroot/10 115 ServerName www.linuxprobe.com 116 <Directory /home/wwwroot/10 > 117 AllowOverride None 118 Require all granted 119 </Directory> 120 </VirtualHost> 121 <VirtualHost 192.168.10.20> 122 DocumentRoot /home/wwwroot/20 123 ServerName bbs.linuxprobe.com 124 <Directory /home/wwwroot/20 > 125 AllowOverride None 126 Require all granted 127 </Directory> 128 </VirtualHost> 129 <VirtualHost 192.168.10.30> 130 DocumentRoot /home/wwwroot/30 131 ServerName tech.linuxprobe.com 132 <Directory /home/wwwroot/30 > 133 AllowOverride None 134 Require all granted 135 </Directory> 136 </VirtualHost> ………………省略部分输出信息……………… systemctl restart httpd semanage fcontext -a -t httpd_sys_content_t /home/wwwroot semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10 semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10/* semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20 semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20/* semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/30 semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/30/* 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/10 context unconfined_u:object_r:home_root_t:s0- >unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/10/index.html context unconfined_u:object_r:home_ root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/20 context unconfined_u:object_r:home_root_t:s0-> unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/20/index.html context unconfined_u:object_r:home_ root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/30 context unconfined_u:object_r:home_root_t:s0-> unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/30/index.html context unconfined_u:object_r:home_ root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 firefox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.10.10 www.linuxprobe.com bbs.linuxprobe.com tech.linuxprobe.com ping -c 4 www.linuxprobe.com PING www.linuxprobe.com (192.168.10.10) 56(84) bytes of data. 64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=1 ttl=64 time=0.070 ms 64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=2 ttl=64 time=0.077 ms 64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=3 ttl=64 time=0.061 ms 64 bytes from www.linuxprobe.com (192.168.10.10): icmp_seq=4 ttl=64 time=0.069 ms --- www.linuxprobe.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2999ms rtt min/avg/max/mdev = 0.061/0.069/0.077/0.008 ms mkdir -p /home/wwwroot/www mkdir -p /home/wwwroot/bbs mkdir -p /home/wwwroot/tech echo "WWW.linuxprobe.com" > /home/wwwroot/www/index.html echo "BBS.linuxprobe.com" > /home/wwwroot/bbs/index.html echo "TECH.linuxprobe.com" > /home/wwwroot/tech/index.html vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息……………… 113 <VirtualHost 192.168.10.10> 114 DocumentRoot "/home/wwwroot/www" 115 ServerName "www.linuxprobe.com" 116 <Directory "/home/wwwroot/www"> 117 AllowOverride None 118 Require all granted 119 </directory> 120 </VirtualHost> 121 <VirtualHost 192.168.10.10> 122 DocumentRoot "/home/wwwroot/bbs" 123 ServerName "bbs.linuxprobe.com" 124 <Directory "/home/wwwroot/bbs"> 125 AllowOverride None 126 Require all granted 127 </Directory> 128 </VirtualHost> 129 <VirtualHost 192.168.10.10> 130 DocumentRoot "/home/wwwroot/tech" 131 ServerName "tech.linuxprobe.com" 132 <Directory "/home/wwwroot/tech"> 133 AllowOverride None 134 Require all granted 135 </directory> 136 </VirtualHost> ………………省略部分输出信息……………… semanage fcontext -a -t httpd_sys_content_t /home/wwwroot semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/www semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/www/* semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/bbs semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/bbs/* semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/tech semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/tech/* restorecon -Rv /home/wwwroot 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/www context unconfined_u:object_r:home_root_t: s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/www/index.html context unconfined_u:object_r: home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/bbs context unconfined_u:object_r:home_root_t: s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/bbs/index.html context unconfined_u:object_r: home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/tech context unconfined_u:object_r:home_root_t: s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/tech/index.html context unconfined_u:object_r: home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 firefox
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105mkdir -p /home/wwwroot/6111 mkdir -p /home/wwwroot/6222 echo "port:6111" > /home/wwwroot/6111/index.html echo "port:6222" > /home/wwwroot/6222/index.html vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息……………… 33 # 34 # Listen: Allows you to bind Apache to specific IP addresses and/or 35 # ports, instead of the default. See also the <VirtualHost> 36 # directive. 37 # 38 # Change this to Listen on specific IP addresses as shown below to 39 # prevent Apache from glomming onto all bound IP addresses. 40 # 41 #Listen 12.34.56.78:80 42 Listen 80 43 Listen 6111 44 Listen 6222 ………………省略部分输出信息……………… vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息……………… 113 <VirtualHost 192.168.10.10:6111> 114 DocumentRoot "/home/wwwroot/6111" 115 ServerName www.linuxprobe.com 116 <Directory "/home/wwwroot/6111"> 117 AllowOverride None 118 Require all granted 119 </Directory> 120 </VirtualHost> 121 <VirtualHost 192.168.10.10:6222> 122 DocumentRoot "/home/wwwroot/6222" 123 ServerName bbs.linuxprobe.com 124 <Directory "/home/wwwroot/6222"> 125 AllowOverride None 126 Require all granted 127 </Directory> 128 </VirtualHost> ………………省略部分输出信息……………… semanage fcontext -a -t httpd_sys_content_t /home/wwwroot semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111 semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6111/* semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222 semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/6222/* 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/6111 context unconfined_u:object_r:home_root_t: s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/6111/index.html context unconfined_u:object_r: home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/6222 context unconfined_u:object_r:home_root_t: s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /home/wwwroot/6222/index.html context unconfined_u:object_r: home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 [root@linuxprobe ~]# systemctl restart httpd Job for httpd.service failed. See 'systemctl status httpd.service' and 'journalctlxn' for details. semanage port -l | grep http http_cache_port_t tcp 8080, 8118, 8123, 10001-10010 http_cache_port_t udp 3130 http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000 pegasus_http_port_t tcp 5988 pegasus_https_port_t tcp 5989 semanage port -a -t http_port_t -p tcp 6111 semanage port -a -t http_port_t -p tcp 6222 semanage port -l| grep http http_cache_port_t tcp 8080, 8118, 8123, 10001-10010 http_cache_port_t udp 3130 http_port_t tcp 6222, 6111, 80, 81, 443, 488, 8008, 8009, 8443, 9000 pegasus_http_port_t tcp 5988 pegasus_https_port_t tcp 5989 systemctl restart httpd firefox mkdir /var/www/html/server echo "Successful" > /var/www/html/server/index.html vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息……………… 129 <Directory "/var/www/html/server"> 130 SetEnvIf User-Agent "Firefox" ff=1 131 Order allow,deny 132 Allow from env=ff 133 </Directory> ………………省略部分输出信息……………… systemctl restart httpd firefox vim /etc/httpd/conf/httpd.conf ………………省略部分输出信息……………… 129 <Directory "/var/www/html/server"> 130 Order allow,deny 131 Allow from 192.168.10.20 132 Order allow,deny 133 Allow from env=ie 134 </Directory> ………………省略部分输出信息……………… systemctl restart httpd firefox
Copyright ©2010-2022 比特日记 All Rights Reserved.