這篇文章主要介紹“Nginx如何配置多端口多域名訪問”,在日常操作中,相信很多人在Nginx如何配置多端口多域名訪問問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Nginx如何配置多端口多域名訪問”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

在邊壩等地區,都構建了全面的區域性戰略布局,加強發展的系統性、市場前瞻性、產品創新能力,以專注、極致的服務理念,為客戶提供成都網站設計、成都網站建設 網站設計制作按需搭建網站,公司網站建設,企業網站建設,品牌網站設計,全網營銷推廣,成都外貿網站建設,邊壩網站建設費用合理。
主域名多端口訪問
在DNS nameserver設置a記錄
將 指向服務器ip
開放所需端口,修改nginx配置文件
比如我們有兩個服務分別開放在80端口和8080端口
如果有iptable,先開放端口:
iptables -a input -ptcp --dport 80 -j accept iptables -a input -ptcp --dport 8080 -j accept
修改配置文件:
#path: /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.xxx.com;
access_log /data/www/log/33.33.33.33_nginx.log combined;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/none.conf;
root /data/www/website/33.33.33.33:80;
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
server {
listen 8080;
server_name a.xxx.com;
access_log /data/www/log/33.33.33.33:8080_nginx.log combined;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/none.conf;
root /data/www/website/33.33.33.33:8080;
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}關鍵就是兩個 server 段配置,你也可以把這兩段拆成兩個配置文件,放到
/etc/nginx/conf.d/
目錄下面;
子域名多端口訪問
這種訪問比較傻,因為你的8080端口的訪問需要 http://xxx.com:8080 這樣的格式;
而且如果有兩個不同的cgi,比如80端口對應一個php web服務, 8080端口對應一個nodejs web服務;而我們的nodejs自帶web服務,已經在8080端口監聽了,這怎么辦?
這個時候我們需要nginx的反向代理功能,并在dns server上面增加一條a記錄,最終實現
www.xxx.com 訪問80端口
a.xxx.com 通過nginx轉發訪問8080端口服務
增加一條a記錄
將 a.xxx.com 指向服務器ip
nginx配置模板如下:
#path: /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.xxx.com;
access_log /data/www/log/33.33.33.33_nginx.log combined;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/none.conf;
root /data/www/website/33.33.33.33:80;
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
server {
listen 80;
listen [::]:80;
server_name a.xxx.com;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header upgrade $http_upgrade;
proxy_set_header connection 'upgrade';
proxy_set_header host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ =404;
}
}nginx重新載入配置文件
nginx -s reload
到此,關于“Nginx如何配置多端口多域名訪問”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注創新互聯網站,小編會繼續努力為大家帶來更多實用的文章!
網頁名稱:Nginx如何配置多端口多域名訪問
URL網址:http://www.yijiale78.com/article44/jdojee.html
成都網站建設公司_創新互聯,為您提供企業建站、網站收錄、微信公眾號、外貿網站建設、建站公司、做網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯