-
远程连接并登录到 Linux 实例。
-
执行命令
cd /etc/nginx/conf.d
打开 Nginx 服务配置文件目录。 -
执行命令
vi 您要创建的域名.conf
创建域名规则配置文件,如示例中的vi www.server110.com.conf
。 -
输入
i
编辑新建的配置文件:-
为每一个域名建立一个单独的配置文件时输入以下内容:
server
{
listen 80; #监听端口设为 80。
server_name www.server110.com; #绑定您的域名。
index index.htm index.html index.php; #指定默认文件。
root /home/www/server110.com; #指定网站根目录。
include location.conf; #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
-
将多个域名规则写进一个共同的配置文件时输入以下内容:
server
{
listen 80; #监听端口设为 80。
server_name www.server110.com; #绑定您的域名。
index index.htm index.html index.php; #指定默认文件。
root /home/www/server110.com; #指定网站根目录。
include location.conf; #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
server
{
listen 80; #监听端口设为 80。
server_name msn.server111.com; #绑定您的域名。
index index.htm index.html index.php; #指定默认文件。
root /home/www/msn.server110.com; #指定网站根目录。
include location.conf; #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
-
为无 WWW 前缀的域名配置规则并加 301 跳转时输入以下内容:
server
{
listen 80;
server_name server110.com;
rewrite ^/(.*) http://www.server110.com/$1 permanent;
}
-
需要为域名添加 404 提示时输入以下内容:
server
{
listen 80; #监听端口设为 80。
server_name www.server110.com; #绑定您的域名。
index index.htm index.html index.php; #指定默认文件。
root /home/www/server110.com; #指定网站根目录。
include location.conf; #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
error_page 404 /404.html;
}
-
-
按 Esc 退出编辑并输入
:wq
保存退出。 -
执行命令
nginx -t
检查配置是否有误,并按照报错提示修复错误。 -
执行命令
service nginx restart
重启 Nginx 服务。 -
执行命令
service nginx reload
重新载入 Nginx 服务。
使用 Nginx 为 Linux 实例绑定多个域名
最新推荐文章于 2022-04-20 11:38:35 发布