婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Nginx配置多端口多域名訪問的實現

Nginx配置多端口多域名訪問的實現

熱門標簽:400電話申請知乎 大連電銷外呼系統運營商 泰州智能外呼系統排名 接電話機器人罵人 外呼系統虛擬號碼 百度地圖標注尺寸無法顯示 長春電銷外呼系統代理商 400電話干嘛怎么申請信用卡 代理外呼系統創業

在一個服務器上部署多個站點,需要開放多個端口來訪問不同的站點,流程很簡單,調試花了2小時,記錄一下:

主域名多端口訪問

在DNS NameServer設置A記錄

將 www.xxx.com 指向服務器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,配置,多,端口,域名,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Nginx配置多端口多域名訪問的實現》相關的同類信息!
  • 本頁收集關于Nginx配置多端口多域名訪問的實現的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 五原县| 雷山县| 中江县| 博客| 常宁市| 鄂托克前旗| 裕民县| 怀远县| 安西县| 西青区| 南和县| 苍南县| 皋兰县| 滁州市| 祁阳县| 济南市| 城口县| 确山县| 咸宁市| 津市市| 安陆市| 乌拉特中旗| 冀州市| 江津市| 龙泉市| 徐州市| 龙陵县| 鄂尔多斯市| 蓬莱市| 英吉沙县| 桦南县| 北碚区| 常山县| 龙门县| 微山县| 红安县| 将乐县| 永仁县| 湘潭市| 务川| 青海省|