nginx虚拟目录实现两个后台使用
生活随笔
收集整理的這篇文章主要介紹了
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 ?訪問不通目錄下的數據
?
轉載于:https://www.cnblogs.com/liuquan/p/7228790.html
總結
以上是生活随笔為你收集整理的nginx虚拟目录实现两个后台使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【168天】黑马程序员27天视频学习笔记
- 下一篇: pt-archiver 数据归档bug