Nginx 구성 다중 사이트 가상 호스트 인스턴스 공유

小云云
풀어 주다: 2018-01-09 09:21:11
원래의
1373명이 탐색했습니다.

이 글은 주로 Nginx로 다중 사이트 가상 호스트를 구성하는 방법을 소개합니다. 도움이 필요한 친구들이 참고하면 도움이 될 것입니다.

Linux Nginx에서 여러 디렉터리에 액세스하기 위해 다른 도메인 이름을 사용한다고 가정합니다. 이 경우 특정 구성은 다음과 같이 웹 사이트 루트 디렉터리가 설정되어 있다고 가정합니다.

1. /var에서 /www/

/var/www/ushark.net
/var/www/ushark.wang
로그인 후 복사

아래에 두 개의 새 디렉토리를 만듭니다. 2. /etc/nginx/nginx.conf

http {
  include    /etc/nginx/mime.types;
  default_type application/octet-stream;
  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';
  access_log /var/log/nginx/access.log main;
  sendfile    on;
  #tcp_nopush   on;
  keepalive_timeout 65;
  #gzip on;
  include /etc/nginx/conf.d/*.conf;   #主要是加入此行,如有则忽略
}
로그인 후 복사

3을 편집합니다. /etc/nginx/conf.d,

/etc/nginx/conf.d/ushark.net.conf
/etc/nginx/conf.d/ushark.wang.conf
로그인 후 복사

4. 다음과 같이 복사하세요. 정보를 2개의 파일로 구성하고, 빨간색 부분만 수정해주세요!!! server_name은 루트와 일치합니다. 즉, 디렉터리와 도메인 이름이 1대1로 일치합니다!!!

server {
  listen    80;
  server_name  www.ushark.net;
  #charset koi8-r;
  #access_log /var/log/nginx/host.access.log main;
  root  /var/www/ushark.net/;
  if (!-e $request_filename){   # rewrite可根据网站需要增删
      rewrite ^/(.*) /index.php last; 
  } 
  location / {
    index index.php index.html index.htm;
  }
  #error_page 404       /404.html;
  # redirect server error pages to the static page /50x.html
  #
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  /var/www/ushark.net/;
  }
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #  proxy_pass  http://127.0.0.1;
  #}
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  location ~* \.php$ {
    fastcgi_index  index.php;
    fastcgi_pass  127.0.0.1:9000;
    include      fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  SCRIPT_NAME    $fastcgi_script_name;
  }
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #  deny all;
  #}
}
로그인 후 복사

5. Nginx

systemctl restart nginx
로그인 후 복사

6. /etc/hosts  편집 !!!

[root@bogon ~]# vi 127.0.0.1    localhost.localdomain localhost
::1       localhost6.localdomain6 localhost6
127.0.0.1    www.ushark.net
127.0.0.1    www.ushark.wang
로그인 후 복사

관련 권장 사항:

nginx nodejs 프록시 서버 구성(mac 환경)

NGINX SSL 양방향 인증 구성

nginx 구성 문제

위 내용은 Nginx 구성 다중 사이트 가상 호스트 인스턴스 공유의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!