linux Nginx VirtualHost 가상 호스트 다 중 사이트 설정

7036 단어
linux  CentOS7
Nginx1.9.9
  nginx     IP         ,                  
  nginx    IP    192.168.155.129
          websuit_a,websuit_b,     websuit_a.com   websuit_a  ,  websuit_b.com   websuit_b  


   nginx                websuit_a websuit_b           PHP  
mkdir -m777 -p /usr/local/nginx/html/websuit_a /usr/local/nginx/html/websuit_b


 websuit_a     index.php  ,       
<?php echo "this is websuit_a";?>
vim /usr/local/nginx/html/websuit_a/index.php


 websuit_b     index.php  ,       
<?php echo "this is websuit_b";?>
vim /usr/local/nginx/html/websuit_b/index.php


 nginx        vhosts_conf                
mkdir -m777 -p /usr/local/nginx/conf/vhosts_conf


     websuit_a.com       ,   websuit_a.conf          
server {
    listen 80;  #      
    server_name websuit_a.com;  #          
    #access_log  logs/host.access.log  main;
    location / {
        root html/websuit_a;  #               /usr/local/nginx/html/websuit_a
        index  index.html index.htm index.php;
        #   rewrite    ,URL             URL                    URL   
        #nginx  .htaccess,    .htaccess         ,  nginx         .htaccess    ,  ,  nginx               ,  .htaccess  
        rewrite ^/(\w+)\.html$ /$1.php;
        rewrite ^/(\w+)/(\w+)$ /$1/$2.php;
    }
    #      
    error_page   404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        root           html/websuit_a;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /usr/local/nginx/html/websuit_a$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ /\.ht {
        deny all;
    }
}
vim /usr/local/nginx/conf/vhosts_conf/websuit_a.conf


   websuit_b.com       ,   websuit_b.conf          
server {
    listen 80;  #      
    server_name websuit_b.com;  #          
    #access_log  logs/host.access.log  main;
    location / {
        root html/websuit_b;  #               /usr/local/nginx/html/websuit_b
        index  index.html index.htm index.php;
        #   rewrite    
        rewrite ^/(\w+)\.html$ /$1.php;
        rewrite ^/(\w+)/(\w+)$ /$1/$2.php;
    }
    #      
    error_page   404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        root           html/websuit_b;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /usr/local/nginx/html/websuit_b$fastcgi_script_name;
        include        fastcgi_params;
    }
    location ~ /\.ht {
        deny all;
    }
}
vim /usr/local/nginx/conf/vhosts_conf/websuit_b.conf


  nginx  
service nginx stop


  nginx     http {}             
include /usr/local/nginx/conf/vhosts_conf/*.conf;
vim /usr/local/nginx/conf/nginx.conf


  nginx
service nginx start


        ,       ,       hosts  ,      
192.168.155.129 websuit_a.com
192.168.155.129 websuit_b.com


            
websuit_a.com,websuit_b.com
    
this is websuit_a,this is websuit_b

좋은 웹페이지 즐겨찾기