使用 Amazon Linux 在新的 Amazon AWS 微型实例上安装此程序。我已经安装了 nginx 和 php7。我似乎无法加载 php。
sudo yum 安装 nginx
sudo yum 安装 php70-fpm
在以下位置创建了文档根目录:
/var/www/html
用户/组是 nginx:nginx
编辑 php-fpm conf 以指向正确的用户/组:
/etc/php-fpm-7.0.d/www.conf
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen.mode = 0664
listen = /var/run/php-fpm/php-fpm.sock
然后我改变了默认的 nginx 配置
/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
index index.php index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
如果我在文档根目录创建一个 php 文件,则只会得到 404。任何 html 页面都可以正常加载。我的 nginx 或 php 的 error.log 中没有任何内容。
答案1
终于找到了解决方案。我瞎了,毕竟这是在 error.log 中。因为我在配置中使用套接字:
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
我错过了另一个需要正确设置的文件:
/etc/nginx/conf.d/php-fpm.conf-7.0
upstream php-fpm {
server 127.0.0.1:9000;
}
改成:
upstream php-fpm {
server unix:/var/run/php-fpm/php-fpm.sock;
}