nginx访问文件重定向

server {
listen 80;
server_name www.test.com;
access_log /data/wwwlogs/www.test.com_nginx.log combined;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/none.conf;
root /data/wwwroot/www.test.com/aaa;
#error_page 404 = /404.html;
#error_page 502 = /502.html;


location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}

rewrite "/js/com.js" /js/com.js.php last;


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
}

 

 

com.js.php

<?php  
require_once(substr($_SERVER['DOCUMENT_ROOT'], 0,strrpos($_SERVER['DOCUMENT_ROOT'], '/')).'/application/config/my_db_conf.php'); 
/**
 * Created by wuyueqiang on 2016/10/26.
 */ 
switch (DEBUG) {
    case 0:
        echo 'var com = "test.test.com";';
        echo 'var murl = "mtest.test.com";';
        break;
    case 1:
        echo 'var com = "www.test.com";';
        echo 'var murl = "m.test.com";';
        break;
    default:
        echo 'var com = "dev.test.com";';
        echo 'var murl = "mdev.test.com";';
        break;
}
 

 

posted on 2017-02-20 11:02  ziyi_ang  阅读(450)  评论(0编辑  收藏  举报

导航