部署子域名

先说说我犯的错误吧,老是忘记域名先要在 DNS 服务器部署,再在 nginx 配置。

 

步骤:

1.将你想用的域名,在 DNS 服务器备案。

举个例子,

shoelesscai.com

en.shoelesscai.com

m.shoelesscai.com

 

2.项目文件夹如何确定?

shoelesscai.com  ../html

en.shoelesscai.com  ../html/en

m.shoelesscai.com  ../html/mobile

 

3.使用 Linux 运行以下代码

我用的 CentOS,主要因为这个版本界面化比较好,很接近 WIndows。

运行 vim /etc/nginx/nginx.conf

 

4.服务器部署如下

http {

/*  server -1 */

server {

    listen 80;

    server_name shoelesscai.com;

    root  ../html;  // 这里要请读者自行补上的,复制是不可用的!

    index index.html;

    location \ {

    }

}

server {

    listen 443;  // https 端口

    server_name shoelesscai.com;

    root  ../html;

    index index.html;

    location \ {

    }
}

 

/*  server -2 */

server {

    listen 80;

    server_name en.shoelesscai.com;

    root  ../html/en;

    index index.html;

    location \ {

    }

}

server {

    listen 443;  // https 端口

    server_name en.shoelesscai.com;

    root  ../html/en;

    index index.html;

    location \ {

    }
}

 

/*  server -3 */

server {

    listen 80;

    server_name m.shoelesscai.com;

    root  ../html/m;

    index index.html;

    location \ {

    }

}

server {

    listen 443;  // https 端口

    server_name m.shoelesscai.com;

    root  ../html/m;

    index index.html;

    location \ {

    }
}

}

 

5. 这里涉及几个问题。

第一,https 必须先配置 80 端口。

第二,如果配置完不用 443 ,则用 page_error 跳转。

注意,https 是针对 SSL 产生的专用端口。

第三,443  端口是可以不部署的,即便你使用了  SSL。具体做法,自定义端口,并且罗列所以可能情况,如果有些情况预计到不能解决,则走  error_page。

 

6.为什么一定要 DNS 服务器配置

我们配置 vim /etc/nginx/nginx.conf

写 server_name,至少 php 知道这是个域名吧。如果 DNS 服务器不配置,php  就不知道这是个域名。

 

 

 

 

 

欢迎关注 ShoelessCai.com 。

 

posted on 2024-07-07 15:17  Mira_2019  阅读(6)  评论(0编辑  收藏  举报