为nginx服务配置虚拟主机,新增两个域名 www.kgc.com 和 www.benet.com,使用http://www.kgc.com/index.php可访问上一题的Discuz论坛页面。(10分) 使用http://www.benet.com则访问/var/www/html目录中的index.html文件的内容,内容自定义。(10分)
时间: 2024-02-04 15:03:10 浏览: 26
首先,您需要在nginx的配置文件中添加两个虚拟主机的配置。在Ubuntu系统中,nginx的主配置文件为/etc/nginx/nginx.conf。在该文件中找到http段,添加以下代码:
```
server {
listen 80;
server_name www.kgc.com;
root /var/www/html/Discuz/upload;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name www.benet.com;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
```
这里的配置如下:
- `server`块表示一个虚拟主机,其中`listen`表示监听的端口号,`server_name`表示虚拟主机的域名,`root`表示虚拟主机的根目录,`index`表示默认访问的文件名。
- 第一个虚拟主机的根目录指向Discuz论坛的上传目录,使用`location`块配置PHP解析。
- 第二个虚拟主机的根目录指向/var/www/html目录,使用`location`块配置静态文件访问。
配置完成后,保存文件并重启nginx服务:
```
sudo systemctl restart nginx
```
接下来,您可以使用http://www.kgc.com/index.php来访问Discuz论坛页面,使用http://www.benet.com来访问自定义的index.html页面。