Nginx doesn't server subfolder api application (php-fpm)

时间:2016-03-04 18:21:18

标签: php angularjs codeigniter nginx

I have following folder structure for my application

- css
- app
- js
- ...
- server (codeigniter)
  -- system
  -- application
  -- index.php
- index.html (angularJS app)

this is my nginx.conf

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

        root /var/www/html/myapp.com/public_html;

        index index.html;

        server_name myapp.com www.myapp.com;

        location / {
              index  index.html;
        }

        location /server/ {
                index /server/index.php;
                try_files $uri /server/index.php/$uri;
        }

        location /twitter/ {
                index /twitter/index.php;
                try_files $uri /twitter/index.php/$uri;
        }

        location ~ \.php {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                include fastcgi_params;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        }

        #deny access to .htaccess files, if Apache's document root
        #concurs with nginx's one
        location ~ /\.ht {
               deny all;
        }
}

And this is the error i'm keep getting

2016/03/04 18:26:02 [error] 4577#0: *4 FastCGI sent in stderr: "Unable to open primary script: /home/valor/development/myapp.com/public_html/server/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.com, request: "GET /server/api/users/isLoggedIn HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.com", referrer: "http://myapp.com/"
2016/03/04 18:26:02 [error] 4577#0: *3 FastCGI sent in stderr: "Unable to open primary script: /home/valor/development/myapp.com/public_html/server/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.com, request: "GET /server/api/categories HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.com", referrer: "http://myapp.com/"
2016/03/04 18:26:03 [error] 4577#0: *3 FastCGI sent in stderr: "Unable to open primary script: /home/valor/development/myapp.com/public_html/server/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: myapp.com, request: "GET /server/api/products/latest/16 HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "myapp.com", referrer: "http://myapp.com/"

Page is displayed correctly i just can reach api resources in sub folder. Can you guy help me out what i'm doing wrong? If you need any additional information's please let me know and i will provide

Thank you

1 个答案:

答案 0 :(得分:0)

基于用户@ semm0(link) 此可能是一个权限问题,可能是由AppArmor引起的。请查看this answer以查看可能的解决方案。我不想窃取答案,因此链接到它。

编辑:现在可能会出现php-fpm配置问题。请使用您喜欢的编辑器打开/etc/php5/fpm/pool.d/www.conf并取消注释以下行:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

并且不要忘记重启php服务器:

service php5-fpm restart