文章目录
- 1、远程连接服务器
- 2、`Nginx`配置域名
- 2.1、为每一个域名建立一个单独的配置文件时输入以下内容:
- 2.2、将多个域名规则写进一个共同的配置文件时输入以下内容:
- 2.3、为无 `WWW` 前缀的域名配置规则并加 `301` 跳转时输入以下内容:
- 2.4、需要为域名添加 `404` 提示时输入以下内容:
- 3、后续操作
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 服务。
最后
以上就是孤独雨最近收集整理的关于Linux Nginx 配置/绑定域名的全部内容,更多相关Linux内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复