gpt4 book ai didi

nginx - 如何在 Amazon EC2 AMI 实例上使用 nginx 一致地设置 PHP-FPM 5.6

转载 作者:可可西里 更新时间:2023-11-01 12:39:17 25 4
gpt4 key购买 nike

我找不到从头开始在 Amazon AMI EC2 实例上的 nginx 上设置 php-fpm 的方法。我知道这不应该那么困难,但是根据 *nix 版本找到不同的答案是令人困惑的。

以下是我认为可行但行不通的浓缩步骤。有没有人有一套在 Amazon AMI EC2 实例中使用 nginx 可靠地设置 php-fpm 的步骤?

我在这篇文章中故意遗漏了 nginx.conf 等,因为它们是默认 yum 存储库中的“库存”安装。

nginx 版本:1.6.2

有没有人有可靠的步骤在 nginx 中为 Amazon AMI EC2 实例设置 php-fpm?我宁愿自己设置,也不愿使用 Amazon 市场中为此设置收费的 AMI。

谢谢

# install packages
yum install -y nginx
yum install -y php56-fpm.x86_64

# enable php in nginx.conf
vi /etc/nginx/nginx.conf
# add index.php at the beginning of index
index index.php index.html index.htm;

# uncomment the php block in nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

# tell php-fpm to run as same account as nginx
vi /etc/php-fpm-5.6.d/www.conf
- change user and group apache to nginx

# allow nginx user to read website files since they are typically owned by root
cd /usr/share/nginx
chown -R nginx:nginx html

# check to see if php works - doesn't with these steps
echo "<?php phpinfo(); ?>" > /usr/share/nginx/info.php

# restart services since we changed things
service nginx restart
service php-fpm-5.6 restart

# verify root path exists and is owned by nginx as we said above
# ls -l /usr/share/nginx/html
-rw-r--r-- 1 nginx nginx 3696 Mar 6 03:53 404.html
-rw-r--r-- 1 nginx nginx 3738 Mar 6 03:53 50x.html
-rw-r--r-- 1 nginx nginx 3770 Mar 6 03:53 index.html
-rw-r--r-- 1 nginx nginx 20 Apr 14 14:01 index.php

# I also verified php-fpm is listening on port 9000 and nginx is setup that way in the nginx.conf
# port 9000 usage is the default and I left it as-is for this question, but I would prefer to use sock once I get this working.

编辑

这是我在nginx错误日志中看到的

2015/04/14 17:08:25 [error] 916#0: *9 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, 
client: 12.34.56.78, server: localhost, request: "GET /index.php HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9000", host: "12.34.56.90"

最佳答案

您在 nginx 错误日志 (/var/log/nginx/errors.log) 中看到了什么?

在提供额外信息(日志)后添加:

在我看来,root 应该是服务器部分而不是位置。

server {
...
root /usr/share/nginx/html;
...
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}

关于nginx - 如何在 Amazon EC2 AMI 实例上使用 nginx 一致地设置 PHP-FPM 5.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29631767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com