nginx 가상 호스트 구축

6793 단어 nginx웹 서버
nginx 가상 호스트 구축
 
[root@web-nginx ~]# cat /etc/redhat-release       시스템 버 전 번호 보기  CentOS release 6.6 (Final)   [root@web-nginx ~]# uname -r                            //print  the  kernel release   2.6.32-504.el6.x86_64   [root@web-nginx ~]# uname -m                          // print the  machine  hardware name   x86_64   [root@web-nginx ~]# rpm -qa gcc gcc-c++   gcc-4.4.7-11.el6.x86_64   gcc-c++-4.4.7-11.el6.x86_64[root@web-nginx ~]# rpm -qa pcre pcre-devel    pcre-7.8-6.el6.x86_64   [root@web-nginx ~]# yum -y install pcre pcre-devel      pcre 라 이브 러 리 설치 (정규 표현 식 호 환) [root@web-nginx ~]# rpm -qa openssl openssl-devel   openssl-1.0.1e-30.el6.x86_64   [root@web-nginx ~]# yum -y install openssl openssl-devel     (안전 한 SSL 프로 토 콜 전송 http) [root@web-nginx ~]# rpm -qa pcre pcre-devel openssl openssl-devel   pcre-7.8-6.el6.x86_64   openssl-1.0.1e-30.el6.11.x86_64   openssl-devel-1.0.1e-30.el6.11.x86_64   pcre-devel-7.8-6.el6.x86_64   [root@web-nginx nginx-1.6.3]# wget http://nginx.org/download/nginx-1.6.3.tar.gz     설치 팩 다운로드 [root@web-nginx nginx-1.6.3]# ls      패키지 다운로드 성공 확인 [root@web-nginx nginx-1.6.3]# tar -zxvf nginx-1.6.3.tar.gz      스트레스 해소 [root@web-nginx nginx-1.6.3]# ls     압축 해제 결과 보기 [root@web-nginx nginx-1.6.3]# cd nginx-1.6.3[root@web-nginx nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module       사용자 정의 설치 설정 [root@web-nginx nginx-1.6.3]# make && make install  컴 파일 설치 [root@web-nginx nginx-1.6.3]# echo $?      실행 결과 보기 0                                                    성공root@web-nginx nginx-1.6.3]# useradd nginx -s /sbin/nologin -M     사용자 만 들 기  [root@web-nginx nginx-1.6.3]# id nginx   사용자 와 그룹 정보 보기 uid = 500 (nginx) gid=500(nginx) groups=500(nginx)[root@web-nginx nginx-1.6.3]# ll /application/nginx-1.6.3/   total 16   drwxr-xr-x. 2 root root 4096 Jul  5 15:43 conf        파일 디 렉 터 리 설정  drwxr-xr-x. 2 root root 4096 Jul  5 15:43 html        사이트 디 렉 터 리  drwxr-xr-x. 2 root root 4096 Jul  5 15:43 logs         로그 파일 디 렉 터 리  drwxr-xr-x. 2 root root 4096 Jul  5 15:43 sbin         실행 파일 디 렉 터 리 [root@web-nginx nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx     편리 하 게 사용 하기 위해 소프트 링크 를 만들다.  [root@web-nginx nginx-1.6.3]# ll /application/   total 4   lrwxrwxrwx. 1 root root   25 Jul  5 15:53 nginx -> /application/nginx-1.6.3/   drwxr-xr-x. 6 root root 4096 Jul  5 15:43 nginx-1.6.3[root@web-nginx nginx-1.6.3]# /application/nginx/sbin/nginx       서비스 시작 [root@web-nginx nginx-1.6.3]# ps -ef |grep nginx |grep -v grep      서비스 프로 세 스 보기  root       4762      1  0 15:55 ?        00:00:00 nginx: master process /application/nginx/sbin/nginx       주 프로 세 스  nginx      4763   4762  0 15:55 ?        00:00:00 nginx: worker process          작업 프로 세 스     [root@web-nginx nginx-1.6.3]# netstat -lntup |grep nginx     포트 는 80tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN     [root@web-nginx nginx-1.6.3]# curl 127.0.0.1        로 컬 브 라 우 저 로그 인 테스트 에 성공 하 였 습 니 다.
Nginx 가상 호스트 설정:
가상 호스트: [root@web-nginx ~]# cd  /application/nginx/conf[root@web-nginx conf]# cp nginx.conf /data/root/backup/      nginx. conf 프로필 백업  [root@web-nginx conf]# egrep -v "#|^$" nginx.conf.default>nginx.conf                                                                                              nginx. conf. default 에 주석 이 없고 빈 줄 이 아 닌 내용 을 nginx. conf [로 내 보 냅 니 다.root@web-nginx conf]# mkdir ../html/www   [root@web-nginx conf]# mkdir ../html/bbs   [root@web-nginx conf]# mkdir ../html/blog   [root@web-nginx conf]# echo "www.etiantian.org" >../html/www/index.html   [root@web-nginx conf]# echo "bbs.etiantian.org" >../html/bbs/index.html      [root@web-nginx conf]# echo "blog.etiantian.org" >../html/blog/index.html[root@web-nginx conf]# cat ../html/{www,bbs,blog}/index.html   www.etiantian.org   bbs.etiantian.org   blog.etiantian.org[root@web-nginx conf]# vim nginx.conf      
worker_processes  1;
   events {
       worker_connections  1024;
   }
   http {
       include       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  logs/access.log  main;
       sendfile        on;
       keepalive_timeout  65;
       server {
           listen       80;
           server_name  www.etiantian.org alias etiantian.org;
           access_log  /app/logs/www_logs/access_www.log  main;
           location / {
               root   html/www;
               index  index.html index.htm;
           }
 
         error_page   500 502 503 504  /50x.html;
           location = /50x.html {
               root   html;
           }
       }
       server {
           listen       80;
           server_name  bbs.etiantian.org;
           access_log  /app/logs/bbs_logs/access_bbs.log  main;
           location / {
               root   html/bbs;
               index  index.html index.htm;
           }
           error_page   500 502 503 504  /50x.html;
           location = /50x.html {
               root   html;
           }
       }
 server {
           listen       80;
           server_name  blog.etiantian.org;
           access_log  /app/logs/blog_logs/access_blog.log  main;
           location / {
               root   html/blog;
               index  index.html index.htm;
           }
  [root@web-nginx conf]# vim /etc/hosts192.168.10.104  www.etiantian.org       etiantian.org      192.168.10.104  bbs.etiantian.org       blog.etiantian.org[root@web-nginx conf]# /application/nginx/sbin/nginx -t   nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok   nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful   [root@web-nginx conf]# /application/nginx/sbin/nginx -s reload   [root@web-nginx conf]# curl blog.etiantian.org   blog.etiantian.org   [root@web-nginx conf]# curl www.etiantian.org    www.etiantian.org   [root@web-nginx conf]# curl bbs.etiantian.org   bbs.etiantian.org   [root@web-nginx conf]# curl etiantian.org       www.etiantian.org [root@web-nginx conf]# ll /app/logs/bbs_logs/   total 4   -rw-r--r--. 1 root root 183 Jul  5 20:50 access_bbs.log   [root@web-nginx conf]# ll /app/logs/blog_logs/   total 4   -rw-r--r--. 1 root root 183 Jul  5 20:50 access_logs.log[root@web-nginx conf]# ll /app/logs/www_logs/   total 4   -rw-r--r--. 1 root root 366 Jul  5 20:56 access_www.log

좋은 웹페이지 즐겨찾기