我正在尝试让nginx将所有以/ embed开头的请求路由到/home/forge/dev.tline.io/embed/index.php
我的Nginx配置:
location /embed {
root /home/forge/dev.tline.io;
try_files /embed/index.php =404;
}
location / {
root /home/forge/dev.tline.io;
index index.html index.htm;
try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
所有请求都转到/embed/index.php
,但它不会运行它下载的php文件。
注意:http://dev.tline.io/embed/index.php
编译未下载
如果添加
,我就可以使用它fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
进入location /embed
,但应该有更好的方法来执行此操作
答案 0 :(得分:0)
请尝试以下代码,
#include <iostream>
#include <cstdlib>
#include <typeinfo>
#include <cassert>
struct default_deleter
{
void operator () (void *p) { free(p); }
operator bool() { return true;}
};
struct do_not_delete
{
void operator () (void const *){}
operator bool() { return true;}
};
template <typename T,typename D = default_deleter>
class unique_ptr
{
public:
typedef T element_type;
typedef D deleter_type;
typedef T * pointer;
explicit unique_ptr(pointer p = 0)
: ptr_(p)
, deleter_(default_deleter())
{
}
unique_ptr(pointer p,deleter_type d)
: ptr_(p)
, deleter_(d)
{
}
~unique_ptr()
{
reset();
}
pointer get() const
{
return ptr_;
}
pointer release()
{
pointer tmp = ptr_;
ptr_ = 0;
return tmp;
}
void reset(pointer p = 0)
{
if (ptr_ != p){
if (ptr_ )
deleter_(ptr_);
ptr_ = p;
}
}
void swap(unique_ptr& u)
{
std::swap(ptr_,u.ptr_);
}
operator bool() const
{
return (ptr_ != 0);
}
#if 0
unique_ptr& operator=(unique_ptr<pointer,deleter_type> && other)
{
this->reset(other.release());
deleter() = other.deleter();
return *this;
}
#endif
private:
unique_ptr(const unique_ptr&);
unique_ptr& operator=(const unique_ptr&);
pointer ptr_;
deleter_type deleter_;
};
void testf(unique_ptr<int const,do_not_delete> ptr)
{
//
}
int main()
{
{
unique_ptr<int> a((int *)malloc(sizeof(int)));
unique_ptr<int,do_not_delete> c(a.get(),do_not_delete());
unique_ptr<int> p(a.release());
}
{
int const s = 10;
testf(unique_ptr<int const,do_not_delete>(&s,do_not_delete()));
}
//unique_ptr<int,void(*)(void *)> a((int *)malloc(sizeof(int)),0);
}
如果这不成功,请尝试适当地切换map $request_uri $rot {
"~ /embed" /home/forge/dev.tline.io/embed/;
default /home/forge/dev.tline.io/;
}
map $request_uri $ind {
"~ /embed" index.php;
default index.html;
}
server {
...
root $rot;
index index.php index.html index.htm;
...
location / {
try_files $uri$args $uri$args/ $uri $uri/ /$ind =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
...
}
位置,并在发现额外'/'的情况下检查错误日志。
答案 1 :(得分:0)
这应该对所有/ embed URL执行/embed/index.php:
server {
root /home/forge/dev.tline.io;
location / {
index index.html index.htm;
try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
}
location /embed {
fastcgi_param SCRIPT_NAME $document_root/embed/index.php;
fastcgi_param SCRIPT_FILENAME $document_root/embed/index.php;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
}
}