httpd
提供http服务
配置文件路径 | /etc/httpd/conf |
服务路径 | /var/www/html |
快速搭建服务
#!/bin/bash
yum -y install httpd
systemctl enable httpd
systemctl restart httpd
firewall-cmd --add-service=http
firewall-cmd --add-service=http --permanent
http虚拟网站
根据需要,一台服务器可能会运行多个网站,这些网站使用同一个IP,因此我们需要对其进行区分。
根据端口区分
#!/bin/bash
mkdir -p /html/81
cat >/etc/httpd/conf.d/new.conf <<EOF
Listen 81
<VirtualHost *:81>
ServerName 1.com
DocumentRoot "/html/81"
<Directory "/html/81">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
EOF
echo "hello world">/html/81/index.html
firewall-cmd --add-port=81/tcp
firewall-cmd --add-port=81/tcp --permanent
根据域名区分
#!/bin/bash
yum -y install httpd
mkdir -p /html/1
cat >/etc/httpd/conf.d/1.conf <<EOF
<VirtualHost *:80>
ServerName 1.com
DocumentRoot "/html/1"
<Directory "/html/1">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
EOF
echo "192.168.10.101 1.com" >>/etc/hosts
echo "hi" >/html/1
systemctl restart httpd
firewall-cmd --add-port=80/tcp
firewall-cmd --add-port=80/tcp --permanent
PHP
Apache调用PHP是调用模块
PHP搭建
#!/bin/bash
yum -y install php
systemctl enable httpd
systemctl restart httpd
echo "<?php phpinfo(); ?>" >/var/www/html/index.php
firewall-cmd --add-service=http
firewall-cmd --add-service=http --permanent
计算机英语
virtualhost | 虚拟主机 |
document | 文件 |