欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Nginx配置多端口多域名訪問(wèn)的實(shí)現(xiàn)

在一個(gè)服務(wù)器上部署多個(gè)站點(diǎn),需要開(kāi)放多個(gè)端口來(lái)訪問(wèn)不同的站點(diǎn),流程很簡(jiǎn)單,調(diào)試花了2小時(shí),記錄一下:

創(chuàng)新互聯(lián)從2013年創(chuàng)立,先為長(zhǎng)垣等服務(wù)建站,長(zhǎng)垣等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為長(zhǎng)垣企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

主域名多端口訪問(wèn)

在DNS NameServer設(shè)置A記錄

將 www.xxx.com 指向服務(wù)器ip

開(kāi)放所需端口,修改nginx配置文件

比如我們有兩個(gè)服務(wù)分別開(kāi)放在80端口和8080端口

如果有iptable,先開(kāi)放端口:

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;
  }
}

關(guān)鍵就是兩個(gè) server 段配置,你也可以把這兩段拆成兩個(gè)配置文件,放到

/etc/nginx/conf.d/

目錄下面;

子域名多端口訪問(wèn)

這種訪問(wèn)比較傻,因?yàn)槟愕?080端口的訪問(wèn)需要 http://xxx.com:8080 這樣的格式;

而且如果有兩個(gè)不同的cgi,比如80端口對(duì)應(yīng)一個(gè)php web服務(wù), 8080端口對(duì)應(yīng)一個(gè)nodejs web服務(wù);而我們的nodejs自帶web服務(wù),已經(jīng)在8080端口監(jiān)聽(tīng)了,這怎么辦?

這個(gè)時(shí)候我們需要Nginx的反向代理功能,并在DNS Server上面增加一條A記錄,最終實(shí)現(xiàn)

  • www.xxx.com 訪問(wèn)80端口
  • A.xxx.com 通過(guò)nginx轉(zhuǎn)發(fā)訪問(wèn)8080端口服務(wù)

增加一條A記錄

將 A.xxx.com 指向服務(wù)器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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

當(dāng)前名稱:Nginx配置多端口多域名訪問(wèn)的實(shí)現(xiàn)
網(wǎng)站鏈接:http://www.chinadenli.net/article18/piiigp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄電子商務(wù)關(guān)鍵詞優(yōu)化品牌網(wǎng)站建設(shè)網(wǎng)站設(shè)計(jì)公司網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名