He probado todas las combinaciones posibles sin éxito.
Mi configuración es básicamente como se describe aquí:
https://devanswers.co/install-php-nginx-ubuntu-20-04/
Estoy en Google Cloud Compute Engine, instancia de VM con Ubuntu 20.04 LTS, PHP 8.0 y Nginx más proxy Cloudflare. SSL habilitado con certificado CF.
FPM8.0 está activo y funciona bien.
Todos los archivos php se ofrecen como descargas en lugar de renderizarlos.
Las páginas HTML funcionan bien.
Cualquier ayuda será muy apreciada.
Hola Adán. Gracias. Aquí tienes:
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;
# }
#}
Luego configuración de 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
Archivo de configuración de 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;
}
¿Puedes publicar tus archivos de configuración de nginx, incluido /etc/nginx/nginx.conf y cualquier configuración de host virtual, así como tu configuración de php-fpm? Además, ¿quién es el propietario de los archivos php y qué permisos tienen?
- Adam Birds
28/03/2021 a las 17:02
------------------------------------
Creo que la ubicación de tu PHP es la siguiente:
/var/run/php/php8.0-fpm.sock; en lugar de /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
}
}
0
------------------------------
eliminar enlace de archivo "predeterminado" que se colocó en /etc/nginx/sites-enabled . Sólo site.conf debe permanecer en este directorio.
systemctl reinicia php8.1-fpm
systemctl reinicia nginx
estado systemctl php8.1-fpm.service - debería estar bien
limpiar el efectivo del navegador o cambiar el nombre del archivo de prueba (info.php ->info2.php)
¡Disfrutar!