搭建LNMP环境(七):绑定域名

admin2022-12-29  143

自己搭建的环境,WEB服务器是Tengine,用起来跟Nginx是一样的,连配置文件基本上都是一样的。

 

那么绑定域名就用Nginx的操作方法应该也可以。折腾一番。

 

度娘查到的资料显示,绑定域名的配置文件有多种写法。

 

 

一、每个域名一个文件的写法

首先打开nginx域名配置文件存放目录:/opt/nginx/conf

如要绑定域名www.abc.com

则在此目录建一个文件:www.abc.com.conf然后在此文件中写规则:

server
{
listen 80;
server_name www.abc.com; #绑定域名
index index.htm index.html index.php; #默认文件
root /home/www/abc.com; #网站根目录
include abc.conf; #调用其他规则,也可去除
}

 

然后重起nginx服务器:

systemctl restart tengine

 

域名就绑定成功了。

 

 

二、多个域名一个文件的写法

一个文件添加多个域名的规则也是一样,只要把上面单个域名重复写下来就ok了:

server
{
listen 80;
server_name www.abc.com; #绑定域名
index index.htm index.html index.php; #默认文件
root /home/www/abc.com; #网站根目录
include abc.conf; #调用其他规则,也可去除
}

server
{
listen 80;
server_name blog.abc.com; #绑定域名
index index.htm index.html index.php; #默认文件
root /home/www/abc.com/blog; #网站根目录
include location.conf; #调用其他规则,也可去除
}

 

同样的,修改之后就要重启WEB服务。

 

 

三、不带www的域名进行301跳转

如果不带www的域名要加301跳转,那也是和绑定域名一样,先绑定不带www的域名,只是不用写网站目录,而是进行301跳转:

server

{
listen 80;
server_name abc.com;
rewrite ^/(.*) https://abc.com/$1 permanent;
}

 

 

四、添加404页面

添加404网页,都可以直接在里面添加:

server
{
listen 80;
server_name www.abc.com; #绑定域名
index index.htm index.html index.php; #默认文件
root /home/www/abc.com; #网站根目录
include abc.conf; #调用其他规则,也可去除
error_page 404 /404.html; #404页面所在的路径
}

 

 

五、域名绑定端口

server
{
listen 80;
server_name abc.com www.abc.com; ##,绑定域名
location / {
proxy_pass http://127.0.0.1:8000; ## 指定端口号 8000
转载请注明原文地址:http://www.198484.com/?read-45.html
0

最新回复(0)