Nginx 405 not allowed to specific '.php'-file

▼魔方 西西 提交于 2020-01-25 11:27:09

问题


I've got a problem with Nginx. I'm just learning it, so it don't know fix this issue.

One of my plugins is trying to POST to a specific url that ends with a 'PHP'-extension. The file isn't location in the root of the folder: 'web'. But in the directory: web/plugins/moxiemanager/api.php. But I'm always receiving a 405.

What do I have to change in the configurations?

Thanks in advance.

My Nginx configurations:

server {
   listen 80;
   server_name kevin.dev;
   root /var/www/html/kevin/web;

location / {
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
}

location ~ ^/(api|app|app_dev|config)\.php(/|$) {
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
}

error_log /var/log/nginx/kevin_error.log;
access_log /var/log/nginx/kevin_access.log;

}


回答1:


This may not be the best way to do it, I'm still finding my way with nginx, but it worked for me just now.

I duplicated my existing location block for app.php to cover the moxia script, so for me adding this did the job...

location ~ moxiemanager/api.php$ {
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SERVER_PORT 80;
    include        /etc/nginx/fastcgi_params;
}

that covers urls ending with moxiemanager/api.php. I'm not 100% sure of the security implications of doing it like this though.



来源:https://stackoverflow.com/questions/21475212/nginx-405-not-allowed-to-specific-php-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!