说明:请确保LNMP环境已经搭建成功,且能正常支持网站的创建和浏览
其他说明:
文章用 Debian 11作为演示系统
Nginx在Debian系统中的默认安装地址:/etc/nginx
Debian系统默认的网站部署根目录:/var/www/html
文章测试用的两个预设测试域名:
wpscale.cn
wpscale.com
-----------------------------------------------------正文------------------------------------------------------------
1. 在系统中注册两个新的假域名
a.打开hosts文件,
sudo nano /etc/hosts
b.在hosts文件的最后添加下面两行,保存关闭
127.0.0.1 wpscale.cn
127.0.0.1 wpscale.com
2. 在Nginx安装目录中的conf.d目录下中新建两个新的配置文件:sitea.conf和siteb.conf
sitea.conf的内容:
server{
listen 81;
listen [::]:81;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name wpscale.cn;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
siteb.conf的内容:
server{
listen 82;
listen [::]:82;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name wpscale.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
3. 在部署网站的根目录中新建一个多域名测试目录:WPScale.cn
sudo mkdir /var/www/html/WPScale.cn
4. 在新目录WPScale.cn目录下新建两个方式测试网站内容的目录:wpscale.cn和wpscale.com
并在其中创建一个index.php测试文件
a. 新建wpscale.cn目录
sudo mkdir /var/www/html/WPScale.cn/wpscale.cn
在wpscale.cn目录下创建index.php测试文件
sudo nano /var/www/html/WPScale.cn/wpscale.cn/index.php
index.php文件的内容为:
<?php echo "Congrats, you are in the wpscale.cn!"; ?>
b. 新建wpscale.com目录
sudo mkdir /var/www/html/WPScale.cn/wpscale.com
在wpscale.com目录下创建index.php测试文件
sudo nano /var/www/html/WPScale.cn/wpscale.com/index.php
index.php文件的内容为:
<?php echo "Congrats, you are in the wpscale.com!"; ?>
5. 重启Nginx服务
sudo systemctl restart nginx
6. 测试效果
在浏览器地址栏输入:wpscale.cn/WPScale.cn/wpscale.cn/index.php来测试域名wpscale.cn
在浏览器地址栏输入:wpscale.com/WPScale.cn/wpscale.com/index.php来测试域名wpscale.com
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。