[英]Nginx downloads php files, instead of executing
我已经尝试了所有可能的组合,但没有成功。 我的设置基本上如下所述: https://devanswers.co/install-php-nginx-ubuntu-20-04/
我在 Google Cloud Compute Engine 上,VM 实例使用 Ubuntu 20.04 LTS、PHP 8.0 和 Nginx 以及 Cloudflare 代理。 SSL 启用 CF 证书。
FPM8.0 处于活动状态并且工作正常。 所有 php 文件都作为下载而不是渲染提供。 HTML 页面工作正常。
任何帮助将不胜感激。
嗨亚当。 谢谢你。 这里是 go:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3,
ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json
application/javascript text/xml application/xml application/xml+rss
text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
然后 php-fpm 配置:
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;
; All relative paths in this configuration file are relative to PHP's
install
; prefix (/usr). This prefix can be dynamically changed by using the
; '-p' argument from the command line.
;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;
[global]
pid = /run/php/php8.0-fpm.pid
include=/etc/php/8.0/fpm/pool.d/*.conf
Nginx 配置文件:
server {
root /var/www/sw;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name mydomainname.com www.mydomainname.com;
location / {
# try_files $uri $uri/ /index.php$is_args$args;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/ssl/cert.pem;
ssl_certificate_key /etc/ssl/key.pem;
ssl_client_certificate /etc/ssl/cloudflare.crt;
ssl_verify_client on;
}
server {
# ... some other code
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
}
}
server {
if ($host = www.mydomainname.com) {
return 301 https://$host$request_uri;
}
if ($host = mydomainname.com) {
return 301 https://$host$request_uri;
}
listen 80 default_server;
listen [::]:80 default_server;
server_name mydomainname.com www.mydomainname.com;
return 404;
}
server {
listen 80;
listen [::]:80;
server_name mydomainname.com www.mydomainname.com;
return 302 https://$server_name$request_uri;
}
我认为您的 php 位置如下: /var/run/php/php8.0-fpm.sock;
而不是/run/php/php8.0-fpm.sock;
server {
# ... some other code
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
# php location is above
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.