开发者社区> 问答> 正文

nginx 配置增加一个固定的重写规则:报错

现有配置如下,想增加 config.js -> 重写到 config.php 且不允许直接访问config.php,怎么搞哦,谢谢哈。。。

server {

    listen              80;
    server_name         js.mydomain.com;


    charset             utf-8;
    set                 $root '/dat/www/js.mydomain.com/public';
    root                $root;


    add_header          Cache-Control no-cache;
    add_header          Cache-Control private;


    index               index.php index.html index.htm;
    try_files           $uri $uri/ @rewrite ;


    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           $root;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

展开
收起
kun坤 2020-06-14 07:01:33 421 0
1 条回答
写回答
取消 提交回答
  • rewrite ^/config.js  /config.php;

    location ~ /config.php {

     internal;

    fastcgi_pass xxx;

    ....


    }


    关键是要用internal, 禁止直接访问。

    2020-06-14 07:01:39
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载