简体   繁体   English

Nginx php mvc 403 禁止

[英]Nginx php mvc 403 forbidden

My nginx server is not allowing for the php files on subfolder giving a 403我的 nginx 服务器不允许子文件夹上的 php 文件给出 403

I have a apache that is running ok with a .htaccess我有一个运行正常的 apache .htaccess

{
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?path=$1 [QSA,L]
RewriteRule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [L]
}

The folder structure is like this :文件夹结构是这样的:

-root
-- Classes
-- Controllers
-- Includes
-- Models
-- Views
--- Home
---- home-view.php
-Index.php

The index is run and open on the browser, but in a button with a link that points to \\views\\home\\ and should load the home-view.php by a controller it's giving me a 403 forbidden, on apache all is working.索引在浏览器上运行并打开,但在一个带有指向 \\views\\home\\ 的链接的按钮中,应该通过控制器加载 home-view.php,它给了我一个 403 禁止,在 apache 上一切正常。

the nginx conf is : nginx conf是:

root /var/www/html;
index index.php index.html index.htm;
server_name cityguide.com wwwcityguide.com

location / {
  if (!-e $request_filename){
    rewrite ^(.+)$ /index.php?path=$1 break;
  }
  rewrite "^/(.*)\.[\d]{10}\.(css|js)$" /$1.$2 break;
  try_files $uri $uri/ =404
}

If you have php-fpm simple provide path in Nginx just like below example.如果你在 Nginx 中有 php-fpm 简单的提供路径,就像下面的例子。 If not you can install php-fpm use following command如果没有,您可以使用以下命令安装 php-fpm

sudo apt-get install phpx-fpm

where x is version of php for example for php7.3 it should be其中 x 是 php 的版本,例如 php7.3 应该是

sudo apt-get install php7.3-fpm

Then add following line in your configuration file然后在您的配置文件中添加以下行

location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

Then you file looks like(considering you are using php7.3)然后你的文件看起来像(考虑到你使用的是php7.3)

server {
    listen 80;
    listen [::]:80;

    . . .

    root /var/www/your folder path;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name example.com www.example.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

      location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        }
}

Also, don't forget to add try_files $uri $uri/ /index.php?$query_string;另外,不要忘记添加try_files $uri $uri/ /index.php?$query_string; this line your location otherwise other routes of MVC not work for you.这条线是您的位置,否则 MVC 的其他路线对您不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM