子文件夹中angular和codeigniter的Nginx配置

时间:2016-10-10 16:33:16

标签: codeigniter nginx

我有以下文件夹结构 在文件夹"red"

/usr/share/nginx/html/myapp.com/

这是我的nginx.conf

-app
-bootstrap
-index.html
-pages
-rest
--application
---controllers
----api
----- Rest classes
----- .....
--system
--vendor
--index.php

nginx访问日志

server {
    listen       80;
    server_name  myapp.com;

    root   /usr/share/nginx/html/myapp.com;

    index  index.html index.htm index.php;

    location / {
        root /usr/share/nginx/html/myapp.com;
        try_files $uri/ $uri index.html =404;
    }

    location /rest/ {
            alias  /usr/share/nginx/html/myapp.com/rest/;
            try_files $uri $uri/ index.php;

            location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
           }
    }

    location ~ \.php$ {
        return 444;
    }
}

我一直在为所有php请求收到444个错误。你能帮我正确设置我的nginx.conf吗?如果您需要任何其他信息,请告诉我,我会提供。提前谢谢!

2 个答案:

答案 0 :(得分:0)

请尝试以下代码,

http {
   ...
   map $request_uri $rot {
      "~/rest" /usr/share/nginx/html/myapp.com/rest/;
      default /usr/share/nginx/html/myapp.com/;
   }
   map $request_uri $ind {
      "~/rest" index.php;
      default index.html;
   }
   ...
   server {
        listen       80;
        server_name  myapp.com;
        rewrite ^/rest(.*) $1 break;
        root   $rot;

        index  index.html index.htm index.php;

        location / {
            try_files $uri/ $uri $ind =404;
        }

        location ~ \.php$ {
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include fastcgi_params;
        }           
    }
   ...
}

答案 1 :(得分:0)

这是我的工作解决方案

server {
    listen       80;
    server_name  myapp.com;

    root   /usr/share/nginx/html/myapp.com;

    index  index.html index.htm index.php;

    location / {
        root /usr/share/nginx/html/myapp.com;
        try_files $uri/ $uri index.html =404;
    }

    location /rest/ {
        alias  /usr/share/nginx/html/myapp.com;
        try_files $uri $uri/ /rest/index.php;

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

    location ~ \.php$ {
        return 444;
    }
}