当前位置:首页 > 虚拟主机 > 正文

apache虚拟主机配置(apache虚拟主机原理)

Apache 虚拟主机配置
虚拟主机允许一台 Apache Web 服务器托管多个网站,每个网站都有自己的域名和配置。
配置要素:

NameVirtualHost:指定虚拟主机的 IP 地址或端口号。
ServerAdmin:指定虚拟主机的管理员电子邮件地址。
ServerName:指定虚拟主机的域名。
DocumentRoot:指定虚拟主机文档的根目录。
ErrorLog:指定虚拟主机的错误日志文件路径。
CustomLog:指定虚拟主机访问日志文件路径。
Options:指定虚拟主机的选项,例如 FollowSymLinks 和 Indexes。
Directory:指定要应用特定配置的特定目录。 例如,Directory /public:表示对 /public 目录应用以下配置。
AllowOverride:指定允许在目录中覆盖虚拟主机配置的指令,例如 Files 和 Options。
Require:指定虚拟主机访问所需的认证或授权规则。 例如,Require all granted:表示允许所有用户访问。
ProxyPass:将请求转发到另一个服务器的代理指令。 例如,ProxyPass /api http://localhost:8080/api:将所有 /api 请求代理到本地主机上的端口 8080。
示例虚拟主机配置:

NameVirtualHost :80
ServerAdmin admin@example.com
ServerName example.com
DocumentRoot /var/www/example.com
ErrorLog /var/log/apache2/example.com-error.log
CustomLog /var/log/apache2/example.com-access.log combined
Options FollowSymLinks Indexes
Directory /var/www/example.com/public
Options -Indexes
AllowOverride Files
Require all granted