[英]How to configure Nginx with php-fpm?
Conclusion : Ok so, now my configuration works, and I think the problem comes from the location of my project, in another user's directory.结论:好的,现在我的配置有效,我认为问题出在我的项目位置,在另一个用户的目录中。 For some reasons, the either nginx or php-fpm is unhappy with it, and doesn't seem to work.
由于某些原因,nginx 或 php-fpm 对此不满意,并且似乎不起作用。
What's still bugging me is that it was a 404 error, not a 403.仍然困扰我的是这是一个 404 错误,而不是 403。
Well, I don't think I will find the final answer.好吧,我想我不会找到最终答案。
I have read zillions of ways to do that, and unfortunately I don't understand what could go wrong.我已经阅读了无数的方法来做到这一点,不幸的是我不明白会出现什么问题。
server {
server_name onepage.cendrounet.com;
listen 80;
root /home/pag/workspace/test_css_platform;
location / {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Nginx is running. Nginx 正在运行。
# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/nginx.service.d
└─php-fpm.conf
Active: active (running) since Fri 2017-12-22 09:48:06 CET; 10h ago
Php-fpm is running : php-fpm 正在运行:
# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2017-12-22 09:40:29 CET; 10h ago
Php-fpm is indeed an unix socket php-fpm 确实是一个unix socket
# ls -l /var/run/php-fpm/www.sock
srw-rw----+ 1 root root 0 déc. 22 09:40 /var/run/php-fpm/www.sock
I am running fedora, but ausearch -m avc
doesn't yield anything.我正在运行 Fedora,但
ausearch -m avc
没有产生任何结果。 (In case I don't understand how selinux works, setenforce 0
hasn't yielded any better resutls. But still, I returned it on.) (以防我不明白 selinux 是如何工作的,
setenforce 0
没有产生任何更好的结果。但是,我还是把它返回了。)
Furthermore, curl -i 'http://onepage.cendrounet.com'
returns此外,
curl -i 'http://onepage.cendrounet.com'
返回
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Fri, 22 Dec 2017 19:11:49 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/7.1.12
Furthermore, my user nginx
belongs to my group pag
.此外,我的用户
nginx
属于我的组pag
。
I have set my permissions like so :我已经像这样设置了我的权限:
# namei -om /home/pag/workspace/css_test_platform/index.php
f: /home/pag/workspace/css_test_platform/index.php
dr-xr-xr-x root root /
drwxr-xr-x root root home
drwxr-x--x pag pag pag
drwxr-xr-x pag pag workspace
drwxrwxr-x pag pag css_test_platform
-rw-rw-r-- pag pag index.php
The configuration of php-fpm is the default one, some details picked : php-fpm 的配置是默认的,挑了一些细节:
user = apache
group = apache
listen = /run/php-fpm/www.sock
listen.acl_users = apache,nginx
listen.allowed_clients = 127.0.0.1
Theorically, user
and group
should be for RPM stuff, but I still have given the pag
group to apache
.理论上,
user
和group
应该用于 RPM 的东西,但我仍然把pag
组给了apache
。
What could cause a 404
error on my index ?什么可能导致我的索引出现
404
错误?
This was on Arch, but it is systemd related.这是在 Arch 上,但它与 systemd 相关。
This solution is for use on a development machine, and for good reasons, you shouldn't run a public site from your /home folder.此解决方案适用于开发机器,出于充分的理由,您不应从 /home 文件夹运行公共站点。
I configured php-fpm and nginx to run as my user.我将 php-fpm 和 nginx 配置为以我的用户身份运行。 Edit the following file, and remove the ProtectHome=true line
编辑以下文件,并删除 ProtectHome=true 行
sudo vi /etc/systemd/system/multi-user.target.wants/php-fpm.service
Reload, and restart everything;重新加载,并重新启动一切;
systemctl daemon-reload
systemctl restart nginx.service
systemctl restart php-fpm.service
You need to add try_files $uri /index.php;
你需要添加
try_files $uri /index.php;
or similar in your location block:或在您的位置块中类似:
location / {
try_files $uri /index.php;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
include fastcgi.conf;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.