Nginx でマルチポートおよびマルチドメイン名アクセスを構成する方法

PHPz
リリース: 2023-05-12 08:43:05
転載
1716 人が閲覧しました

プライマリ ドメイン名へのマルチポート アクセス

DNS ネームサーバーにレコードを設定します

サーバー ip

を指定して必要なポートを開き、nginx 構成ファイルを変更します

たとえば、ポートで 2 つのサービスが開いています。 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;
  }
}
ログイン後にコピー

重要なのは、2 つのサーバー セクションを設定することです。これら 2 つのセクションを 2 つの構成ファイルに分割し、

/etc/nginx/conf.d/
ログイン後にコピー

ディレクトリの下に置くこともできます;

サブドメイン名マルチポート アクセス

# #8080 ポートへのアクセスには http://xxx.com:8080; という形式が必要なため、この種のアクセスは愚かです;

そして、たとえば 2 つの異なる CGI がある場合、ポート 80 は PHP Web に対応します。サービス、およびポート 8080 は、nodejs Web サービスに対応し、nodejs には、すでにポート 8080 でリッスンしている Web サービスが付属しています。

現時点では、nginx のリバース プロキシ機能が必要で、最終的に

  • www.xxx.com アクセス ポート 80# を実現するために、DNS サーバーにレコードを追加します。

  • ##a.xxx.com nginx 転送を通じて 8080 ポート サービスにアクセスします
レコードを追加します


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 でマルチポートおよびマルチドメイン名アクセスを構成する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:yisu.com
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!