社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  NGINX

允许使用Symfony 4和nginx执行index.php之外的其他php脚本

DerpyNerd • 4 年前 • 968 次点击  

给定以下文件夹结构

- www/website
-- public
--- index.php
--- otherscript.php

以及下面的nginx.conf

server {
    listen          8000;
    server_name     localhost;
    root            /www/website/public;
    index           index.php;

    # optionally disable falling back to PHP script for the asset directories;
    # nginx will return a 404 error when files are not found instead of passing the
    # request to Symfony (improves performance but Symfony's 404 page is not displayed) 
    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    # would always refer to index.php (server directive)
    location ~ \.php$ {
        ## tried this - no dice
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        index $fastcgi_script_name;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }
}

我希望能够在不重定向到index.php的情况下执行localhost:8000/otherscript.php。

我怎么能不破坏symfony的路由呢?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54936
 
968 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Danila Vershinin
Reply   •   1 楼
Danila Vershinin    4 年前

类似 /index.php fastcgi_params 文件,所以:

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9001;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
}

一定要放这个 location ~ ^/index\.php(/|$) { 因为regex位置是按配置中的存在顺序匹配的。