>  기사  >  운영 및 유지보수  >  Nginx에서 다중 포트 및 다중 도메인 이름 액세스를 구성하는 방법

Nginx에서 다중 포트 및 다중 도메인 이름 액세스를 구성하는 방법

PHPz
PHPz앞으로
2023-05-12 08:43:051717검색

기본 도메인 이름에 대한 다중 포트 액세스

DNS 네임서버에 레코드를 설정하세요

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

핵심은 두 개의 서버 섹션을 구성하는 것입니다. 또한 이 두 섹션을 두 개의 구성 파일로 분할하십시오.

하위 도메인 이름 다중 포트 액세스


이런 종류의 액세스는 어리석은 일입니다. 8080 포트에 액세스하려면 http: //xxx.com:8080;

그리고 예를 들어 두 개의 다른 cgi가 있는 경우 포트 80은 PHP 웹 서비스에 해당하고 포트 8080은 nodejs 웹 서비스에 해당하며 nodejs에는 다음과 같은 웹 서비스가 제공됩니다. 이미 포트 8080에서 수신 대기 중입니다. 어떻게 해야 합니까?

이제 우리는 nginx의 역방향 프록시 기능이 필요하고 DNS 서버에 레코드를 추가하고 마침내

    www.xxx.com을 달성하여 nginx를 통해 포트 80
  • a.xxx.com에 액세스합니다. 8080 포트 서비스 전달
레코드 추가


point a.xxx.com을 서버 ip

nginx 구성 템플릿은 다음과 같습니다.

/etc/nginx/conf.d/
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에서 다중 포트 및 다중 도메인 이름 액세스를 구성하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제