文章目录
1、远程连接服务器
2、Nginx
配置域名
执行命令 vi /etc/nginx/conf.d/**.conf
打开 Nginx
服务配置文件
2.1、为每一个域名建立一个单独的配置文件时输入以下内容:
server
{
listen 80; #监听端口设为 80。
server_name www.server110.com; #绑定您的域名。
index index.htm index.html index.php; #指定默认文件。
root /home/www/server110.com; #指定网站根目录。
include location.conf; #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
2.2、将多个域名规则写进一个共同的配置文件时输入以下内容:
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.server111.com; #绑定您的域名。
index index.htm index.html index.php; #指定默认文件。
root /home/www/server111.com; #指定网站根目录。
include location.conf; #当您需要调用其他配置文件时才粘贴此项,如无需要,请删除此项。
}
2.3、为无 WWW
前缀的域名配置规则并加 301
跳转时输入以下内容:
server
{
listen 80;
server_name server110.com;
rewrite ^/(.*) http://www.server110.com/$1 permanent;
}
2.4、需要为域名添加 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;
}
3、后续操作
-
按 Esc 退出编辑并输入
:wq
保存退出。 -
执行命令
nginx -t
检查配置是否有误,并按照报错提示修复错误。 -
执行命令
systemctl restart nginx
重启 Nginx 服务。 -
执行命令
systemctl reload nginx
重新载入 Nginx 服务。