hostnamectl set-hostname lh.test.com
cat /etc/hosts
安装 Apache HTTP 服务器
yum install httpd
启动和自动启动
apachectl start
systemctl enable httpd
检查配置错误
apachectl configtest
虚拟主机
mkdir -p /www/mysite1.com/logs
mkdir -p /www/mysite1.com/html
echo "MySite1.com Test file" > /www/mysite1.com/html/test.txt
mkdir -p /www/mysite2.com/logs
mkdir -p /www/mysite2.com/html
echo "MySite2.com Test file" > /www/mysite2.com/html/test.txt
文件结构
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.mysite1.com
Serveralias mysite1.com
DocumentRoot /www/mysite1.com/html
ErrorLog /www/mysite1.com/logs/mysite1.com-error_log
</VirtualHost>
<VirtualHost *:80>
ServerName www.mysite2.com
Serveralias mysite2.com
DocumentRoot /www/mysite2.com/html
ErrorLog /www/mysite2.com/logs/mysite2.com-error_log
</VirtualHost>
apachectl restart
setenforce Permissive
cat /etc/hosts
127.0.0.1 mysite1.com mysite1
127.0.0.1 mysite2.com mysite2
<Directory "/www">
AllowOverride None
Require all granted
</Directory>
私有目录(用密码登陆看)
创建一个新目录并在其中放置一个文件
mkdir /www/mysite1.com/html/private
echo "MySite1.com Private Test file" > /www/mysite1.com/html/private/test.txt
<Directory "/www/mysite1.com/html/private">
AuthType basic
AuthName "Private Access"
AuthUserFile "/www/mysite1.com/html/private/.htpasswd"
Require valid-user
Order allow,deny
Allow from all
</Directory>
创建用户和组进行访问
groupadd webdevs
useradd -g webdevs user1
useradd -g webdevs user2
chown -R apache.webdevs /www/mysite1.com/html
chmod -R 775 /www/mysite1.com/html
chmod -R g+s /www/mysite1.com/html
passwd user1
http://mysite1.com/private/test.txt
echo "Test by user1" > /www/mysite1.com/html/group-test.txt
部署基本 CGI 应用程序
mkdir /www/mysite2.com/html/gci-bin
vim helloworld.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "helloWorld!";
chown apache.apache helloworld.pl
chmod u+x helloworld.pl
ScriptAlias /cgi-bin/ /www/mysite2.com/html/gci-bin/
Options +ExecCGI
AddHandler cgi-script .pl .cgi