[AngularJS]Nginx 不子文件夹服务器 api 应用程序 (php fpm)

发布时间: 2017/4/16 17:49:54
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

有以下几个我的应用程序文件夹结构

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

这是我的 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;
        }
}

这是我一直的错误得到

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/"

显示页面正确我只可以达到 api 资源中的子文件夹。 你这家伙能帮我出什么错了吗? 如果你需要任何额外信息的请让我知道,我会提供

谢谢

解决方法 1:

基于用户 @semm0 (链接),这可能是权限的问题,可能造成 AppArmor。请查看这个答案看到可能的解决办法。我不想偷的答案,因此链接到它。

编辑︰ 出现的问题可能现在从 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
官方微信
官方QQ群
31647020