Nginx 虚拟主机代码
server {
listen 80;
#listen [::]:80;
root /var/www/test1;
include enable-php.conf
index index.html index.htm index.php;
server_name test1.test.com;
}
server {
listen 80;
#listen [::]:80;
root /var/www/test2;
include enable-php.conf
index index.html index.htm index.php;
server_name test2.test.com;
}
两个虚拟主机监听相同的 80 端口,根目录分别为 /var/www/test1 和 /var/www/test2。都包含了 enable-php.conf 文件以开启PHP支持。索引文件为 index.html、index.htm 和 index.php。
通过 server_name 指令分别定义了两个主机名。Nginx收到请求后,会根据请求头中的 Host 字段来匹配 server_name ,从而将请求发送到对应的虚拟主机进行处理。
这样可以实现在一台服务器上部署多个网站,通过不同域名来访问不同的网站内容。并可以针对每个站点进行独立的配置。
本文介绍Nginx如何通过监听80端口,设置不同根目录和server_name,实现通过域名访问不同网站,并启用PHP功能。每个站点配置独立。
504

被折叠的 条评论
为什么被折叠?



