問題描述
通過配置nginx可以設置一個ip地址下面通過不同的端口訪問不同的web應用,但是時間長了之后端口號和應用之間的關系就很模糊了。
如 http://120.79.79.xx:9001 和foreign.xxx.xin 雖然這兩個網址都是指向同一個網站,但是后者顯然望文生義,比前者好很多。同時在網站SEO中,后者也比前者的權重更高。
基本知識
頂級域名:.com .cn
二級域名:baidu.com sina.com ,這其中baidu 和sina就是二級域名
三級域名:zhidao.baidu.com 其中zhidao就是三級域名
基本步驟
-
設置地址解析
-
配置nginx 監聽
-
配置nginx 跳轉
創建地址解析
筆者使用的阿里云,登錄到阿里云后臺后,新增a記錄,將三級域名名稱填入到主機記錄中,具體填寫方法可以參考下圖
配置nginx
修改 /etc/nginx/sites-aviablable中的default 文件,完整代碼如下:
server?{ ??listen?80?default_server; ??listen?[::]:80?default_server; ??root?/var/www/html/wordpress; ??index?index.php?index.html?index.htm?index.nginx-debian.html; ??server_name?www.xxxx.xin; ??location?/?{ ????try_files?$uri?$uri/?=404; ??} ??location?~?.php$?{ ????include?snippets/fastcgi-php.conf; ????fastcgi_pass?unix:/run/php/php7.0-fpm.sock; ??} ??location?~?/.ht?{ ????deny?all; ??} } #服務2 server?{ ??listen?80; ??server_name?foreign.xxx.xin; ??location?/?{ ????proxy_pass?http://120.79.xx.xx:9000/; ??} }
兩個服務都是監聽的同一個端口80,但是服務2 的server_name 和新設置的地址解析保持一致。然后設定proxy_pass 將80端口獲取到的信息轉發到9000端口。
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END