国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Nginx配置二級域名的方法實現

瀏覽:164日期:2023-06-15 15:23:37
目錄
  • 1、原始配置文件如下
  • 2、配置二級域名

當一個域名需要使用在兩個項目上后,我們就需要使用到二級域名,在 Nginx 中配置二級域名如下:

1、原始配置文件如下

worker_processes ?1;

events {
? ? worker_connections ?1024;
}

http {
? ? include ? ? ? mime.types;
? ? default_type ?application/octet-stream;

? ? sendfile ? ? ? ?on;
?? ?
? ? keepalive_timeout ?65;

? ? server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?localhost;

? ? ? ? location / {
? ? ? ? ? ? root ? html;
? ? ? ? ? ? index ?index.html index.htm;
? ? ? ? }

? ? ? ? error_page ? 500 502 503 504 ?/50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root ? html;
? ? ? ? }
? ? }

}

這是解壓后的 nginx.conf 文件,可以看出,當前 nginx 監聽的是 80 端口,它的服務名為 localhost,假如我們的域名為:baidu.com,那我們輸入:localhost.baidu.com 也是可以訪問的

2、配置二級域名

對于我們剛才理解的服務名,假如我們的域名為:baidu.com,我們需要配置的二級域名為 asurplus.baidu.com,我們的配置文件如下

worker_processes ?1;

events {
? ? worker_connections ?1024;
}

http {
? ? include ? ? ? mime.types;
? ? default_type ?application/octet-stream;

? ? sendfile ? ? ? ?on;
?? ?
? ? keepalive_timeout ?65;

? ? server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?localhost;

? ? ? ? location / {
? ? ? ? ? ? root ? html;
? ? ? ? ? ? index ?index.html index.htm;
? ? ? ? }

? ? ? ? error_page ? 500 502 503 504 ?/50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root ? html;
? ? ? ? }
? ? }
?? ?
?? ?server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?asurplus.baidu.com;

? ? ? ? location / {
?? ??? ??? ?proxy_pass http://127.0.0.1:8081;
? ? ? ? }
? ? }

}

到 sbin 目錄,執行命令重啟 nginx

./nginx -s reload

我們新增了一個服務,監聽的依然是 80 端口,我們的服務名變成了我們的二級域名:asurplus,并轉發到了我們的 8081 端口,從而完成了二級域名的配置

到此這篇關于Nginx配置二級域名的方法實現的文章就介紹到這了,更多相關Nginx配置二級域名內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: Nginx
主站蜘蛛池模板: 稻城县| 康平县| 黑山县| 黑山县| 马关县| 新邵县| 乌兰浩特市| 土默特右旗| 恭城| 广东省| 班戈县| 馆陶县| 南部县| 霍城县| 扬州市| 汪清县| 南召县| 普定县| 高要市| 大悟县| 阿尔山市| 汉沽区| 台中县| 清新县| 巨野县| 丹阳市| 神农架林区| 札达县| 樟树市| 福贡县| 化德县| 调兵山市| 会宁县| 册亨县| 正安县| 郓城县| 长垣县| 九龙县| 桓台县| 开封市| 清河县|