设置Apache虚拟主机主要有两种方法:基于域名和基于端口。以下是详细的步骤:
sudo apt-get update
sudo apt-get install apache2
sudo yum install httpd
/etc/apache2/httpd.conf 或 /etc/httpd/conf/httpd.conf。IncludeOptional sites-enabled/*.conf
/etc/apache2/sites-available/ 目录下创建一个新的配置文件,例如 example.com.conf,并添加以下内容:<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com
<Directory /var/www/html/example.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>
/etc/apache2/sites-enabled/ 目录:sudo ln -s /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-enabled/
sudo a2ensite example.com.conf
sudo systemctl reload httpd
http://example.com,如果看到example.com的网站内容,则说明配置成功。sudo apt-get update
sudo apt-get install apache2
sudo yum install httpd
/etc/apache2/httpd.conf 或 /etc/httpd/conf/httpd.conf。IncludeOptional sites-enabled/*.conf
/etc/apache2/conf.d/ 目录下创建一个新的配置文件,例如 virtualhost-ports.conf,并添加以下内容:<VirtualHost 10.0.0.71:80>
DocumentRoot /var/www/html/80
</VirtualHost>
<VirtualHost 10.0.0.71:81>
DocumentRoot /var/www/html/81
</VirtualHost>
sudo ufw allow 'Apache Full'
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=81/tcp
sudo firewall-cmd --reload
sudo systemctl restart apache2
sudo systemctl restart httpd
http://10.0.0.71:80 和 http://10.0.0.71:81,分别访问不同端口的网站,确认配置成功。请注意,以上信息仅供参考,具体操作可能会因不同的Linux发行版和Apache版本而有所差异。在配置过程中,请根据实际情况进行调整。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。