日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

将域名绑定到ip上,并实现访问不同二级子域名对应不同目录

發布時間:2023/12/4 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 将域名绑定到ip上,并实现访问不同二级子域名对应不同目录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、將域名綁定到ip上

1、環境介紹:阿里云服務器ESC(美國硅谷)

2、購買域名

3、備案

注:由于我買的是美國地區服務器,所以不用備案,如果買的國內服務器,這里需要添加一個備案操作。

4、域名實名認證

5、將域名綁定到云服務器公網ip

阿里云官網域名解析地址:https://dc.console.aliyun.com/next/index#/domain/list/all-domain

5.1、對購買的域名進行解析(點擊解析按鈕)


5.2、進入解析域名頁面后,點擊添加記錄按鈕


看上圖,可以清晰的看出來,我綁定了5個子域名,現在訪問子域名,就直接訪問我的ip所在的云服務器了。

到此,將域名綁定到ip地址的操作就完成了,剩下的就需要在我們云服務器上進行相應操作了。



二、實現瀏覽器訪問不同子域名,服務器進入不同子目錄

環境介紹:centos7.4、LNMP

注:上面將域名解析后,如果我們不在本地nginx進行配置,訪問的就是nginx的默認目錄,為了實現不同子域名對應不同目錄,我們就需要對nginx進行相應SERVER的配置。

1、使用的是yum安裝的nginx,這里直接配置nginx子配置文件就可以了。( /etc/nginx/conf.d 文件夾下)


注:yum安裝nginx??https://blog.csdn.net/m_nanle_xiaobudiu/article/details/80640293


在這里,我將www.a.xiaobudiu.conf 和 www.b.xiaobudiu.conf 代碼展示出來。

www.a.xiaobudiu.top.conf 代碼:

server { listen 80; server_name www.a.xiaobudiu.top; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /data/main; index index.html index.htm; }#error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }# proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }

?

www.b.xiaobudiu.top.conf 代碼:

server { listen 80; server_name www.b.xiaobudiu.top; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /data/b; index index.html index.htm; }#error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }# proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }

注:nginx.conf 我沒進行改動,yum安裝之后是什么樣就是什么樣。為了測試方便,我這里只對conf.d下的子配置文件進行了更改。


2、到這里,其實配置已經結束了,systemctl restart nginx 重啟一下nginx,清除一下瀏覽器緩存,現在就可以在瀏覽器中看到效果了。

注意:想要實現瀏覽器訪問不同子域名,對應不同文件夾的效果,域名解析和nginx配置文件一定要兩者都有,瀏覽器訪問時,才會訪問到對應目錄。(按照上面的步驟來操作,就沒問題了)



三、效果演示


1、訪問www.a.xiaobudiu.top



2、訪問www.b.xiaobudiu.top


總結

以上是生活随笔為你收集整理的将域名绑定到ip上,并实现访问不同二级子域名对应不同目录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。