我已经看到更多的人有同样的问题,但他们的解决scheme没有为我工作。
我有centos 7 + nginx + php-fpm(版本7.1)。 当我尝试访问我的虚拟主机时,我得到“找不到文件”。 由php-fpm触发,这是我在nginx日志中看到的:
2017/02/27 11:18:54 [error] 7540#7540: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.56.1, server: site.dev, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "site.dev"
php-fpm和nginx都与nginx用户一起运行
root 7539 0.0 0.0 45704 988 ? Ss 11:18 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 7540 0.0 0.1 46292 3220 ? S 11:18 0:00 nginx: worker process nginx 8478 0.0 0.4 470848 8192 ? S 11:18 0:00 php-fpm: pool www nginx 8479 0.0 0.3 470452 7252 ? S 11:18 0:00 php-fpm: pool www nginx 8480 0.0 0.3 470452 7256 ? S 11:18 0:00 php-fpm: pool www nginx 8481 0.0 0.3 470452 7256 ? S 11:18 0:00 php-fpm: pool www nginx 8482 0.0 0.3 470452 7260 ? S 11:18 0:00 php-fpm: pool www root 8532 0.0 0.0 112668 960 pts/0 R+ 11:29 0:00 grep --color=auto nginx
我读了该文件夹需要由php-fpm用户访问,所以我改变了文件夹的权限到777:
drwxrwxrwx. 9 501 games 306 feb 26 20:45 . drwxrwxrwx. 22 501 games 748 feb 26 20:45 .. -rwxrwxrwx. 1 501 games 1189 feb 24 21:23 app_dev.php -rwxrwxrwx. 1 501 games 2092 feb 17 00:42 apple-touch-icon.png -rwxrwxrwx. 1 501 games 631 feb 24 21:23 app.php drwxrwxrwx. 2 501 games 68 feb 17 00:50 bundles -rwxrwxrwx. 1 501 games 21486 feb 26 20:45 config.php -rwxrwxrwx. 1 501 games 6518 feb 17 00:42 favicon.ico -rwxrwxrwx. 1 501 games 116 feb 17 00:42 robots.txt
我不明白为什么老板是“游戏”,这是一个stream浪VM顺便说一句。
这里是我的虚拟主机configuration文件:
server { listen 80; server_name sellbytel.dev; return 301 https://site.dev$request_uri; } server { listen 443 ssl; server_name site.dev; root /var/www/site/web; ssl_certificate /etc/nginx/ssl/ssl_certificate.crt; ssl_certificate_key /etc/nginx/ssl/ssl_certificate.key; client_max_body_size 50M; access_log /var/log/nginx/site.dev.access.log; error_log /var/log/nginx/site.dev.error.log error; # strip app.php/ prefix if it is present rewrite ^/app\.php/?(.*)$ /$1 permanent; ## Static files are served directly. location \/images\/(.*)$ { expires max; log_not_found off; access_log off; ## No need to bleed constant updates. Send the all shebang in one ## fell swoop. tcp_nodelay off; ## Set the OS file cache. open_file_cache max=1000 inactive=120s; open_file_cache_valid 45s; open_file_cache_min_uses 2; open_file_cache_errors off; } location / { index app.php; try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app.php/$1 last; } location ~ ^/(app|app_dev|config)\.php(/|$) { 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 on; fastcgi_intercept_errors on; } }
设置为/var/www/site/web所有者的用户不存在,因为它似乎。 将所有者更改为nginx – 运行nginx的用户:
sudo chown -R nginx:nginx /var/www/site/web
改变后重新启动nginx,你应该准备好了。