一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

云服務器|WEB服務器|FTP服務器|郵件服務器|虛擬主機|服務器安全|DNS服務器|服務器知識|Nginx|IIS|Tomcat|

服務器之家 - 服務器技術 - Nginx - Nginx配置多端口多域名訪問的實現

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

2020-03-10 22:24Living a Simple Life is a Happ Nginx

這篇文章主要介紹了Nginx配置多端口多域名訪問的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

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

主域名多端口訪問

在DNS NameServer設置A記錄

將 www.xxx.com 指向服務器ip

開放所需端口,修改nginx配置文件

比如我們有兩個服務分別開放在80端口和8080端口

如果有iptable,先開放端口:

?
1
2
iptables -A INPUT -ptcp --dport 80 -j ACCEPT
iptables -A INPUT -ptcp --dport 8080 -j ACCEPT

修改配置文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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 段配置,你也可以把這兩段拆成兩個配置文件,放到

?
1
/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配置模板如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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重新載入配置文件

?
1
nginx -s reload

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://happy123.me/blog/2019/11/18/nginxpei-zhi-duo-duan-kou-duo-yu-ming-fang-wen/

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 好吊色永久免费视频大全 | 欧美专区视频 | 精品免费视在线观看 | 欠操h | 精品久久久噜噜噜久久7 | 亚洲精品在线免费 | 美国玩尿眼道videos | 日韩国产成人精品视频人 | 超级乱淫变态伦短篇小说全集 | 九九热在线免费观看 | 男人的j放进女人的p全黄 | 欧美一区二区三区综合色视频 | 欧美三级做爰全过程 | 亚洲欧美一区二区三区不卡 | 精品久久免费视频 | 毛片在线看网站 | 亚洲精品久久久久福利网站 | 毛片免费在线视频 | 国产精品久久久久网站 | 国产一级黄色录像 | 完整秽淫刺激长篇小说 | 俄罗斯毛片免费大全 | www.四虎com| 精品久久免费视频 | 亚洲国产精品久久精品成人网站 | 69堂最新地域网名 | 俄罗斯图书馆无打码久久 | 麻豆视频网| 青草视频在线观看免费资源 | 91aaa免费免费国产在线观看 | 国产清纯女高中生在线观看 | 俄罗斯男男激情1069gay | 女人把扒开给男人爽的 | 色呦阁 | 朝鲜女人free性hu | 人与动人物性行为zozo共患病 | 秋霞黄色网 | 国产精品视频网 | 国产精品模特hd在线 | leslessexvideos日本 | 欧美18-19sex性处视频 |