nginx虚拟目录实现两个后台使用

购买了阿里云机器,准备搭建一套备份的后台,由于资源有限所以将两个后台搭建到一组SLB下的两台WEB上。

使用软件:NGINX+PHP

root@xx conf.d]# yum install php-fpm nginx

更改nginx.conf文件,我将server信息全部注释,http下include到/etc/nginx/conf.d/*.conf下,这样清晰一些~

root@xx conf.d]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;    #包含了我配置虚拟目录的文件


}

[root@xx conf.d]# 

 

在虚拟目录下创建了两个后台的.conf文件

[root@xx conf.d]# ll /etc/nginx/conf.d/
total 8
-rw-r--r-- 1 root root 516 Jul 24 13:54 aaa.com.conf
-rw-r--r-- 1 root root 556 Jul 24 13:55 bbb.com.conf
[root@xx conf.d]# 

 

两个配置文件分别如下:

[root@xx conf.d]# cat bbb.com.conf 
server {
    listen       80;                        
    server_name bbb.com;    
    root  /letv/www/bbbz;             
    index index.html index.htm index.php;   
    location /abc/ {
	index index.php;
	if (!-e $request_filename){
		rewrite ^/abc/(.*)$ /hotel/index.php?s=$1 last;
		break;
    	}
    }
    location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}
[root@xx conf.d]# 

  

[root@xx conf.d]# cat aaa.com.conf 
server {
    listen       80;                        
    server_name aaa.com;    
    root  /letv/www/aaa;             
    index index.html index.htm index.php;   
    location /abc/ {                         #数据目录的匹配
	index index.php;
	if (!-e $request_filename){
		rewrite ^/abc/(.*)$ /hotel/index.php?s=$1 last;
		break;
    	}
    }
    location ~ \.php$ {            #正则表达php文件用fastcgi解析
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}
[root@xx conf.d]# 

  

测试 aaa.com  bbb.com  访问不通目录下的数据

 

posted @ 2017-07-24 14:34  Quan7  阅读(316)  评论(0编辑  收藏  举报