https://github.com/jeijei4/configurar_nginx
Configurar Nginx con php-fpm y obtener la URI con PATH_INFO
https://github.com/jeijei4/configurar_nginx
http2 nginx path-info php-fpm php81 ssl-certificate uri
Last synced: 3 months ago
JSON representation
Configurar Nginx con php-fpm y obtener la URI con PATH_INFO
- Host: GitHub
- URL: https://github.com/jeijei4/configurar_nginx
- Owner: jeijei4
- Created: 2023-07-05T14:54:57.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-11T16:47:09.000Z (almost 3 years ago)
- Last Synced: 2025-03-13T03:15:41.418Z (over 1 year ago)
- Topics: http2, nginx, path-info, php-fpm, php81, ssl-certificate, uri
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Configurar Nginx
### Ajustar php-fpm:
/etc/php-fpm.d/www.conf
```ini
[www]
user = nginx
group = nginx
listen = /run/php-fpm/www.sock
; listen = 127.0.0.1:9000
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
listen.acl_users = nginx
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
```
### Configuración básica de Nginx con PATH_INFO:
/etc/nginx/nginx.conf
```nginx
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name demo.localhost;
# Prevent nginx HTTP Server Detection
server_tokens off;
# Enforce HTTPS
return 301 https://$server_name$request_uri;
#return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name demo.localhost;
root "/var/www/html/proyect/public";
ssl_certificate "/ssl/certificate.crt";
ssl_certificate_key "/ssl/certificate.key";
ssl_trusted_certificate "/ssl/CA.crt";
server_tokens off; # Prevent nginx HTTP Server Detection
index index.php index.html /index.php$request_uri;
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param PATH_INFO $path_info;
fastcgi_param PATH_TRANSLATED $document_root$path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location / {
try_files $uri $uri/ /index.php$request_uri;
}
location ~ /\. {
deny all;
}
}
```
## Obtener la URI en PHP ^8.1
```php
$uri = $_SERVER['PATH_INFO'] ?? '/';
echo $uri;
```
### Reiniciar
```shell
systemctl restart nginx php-fpm
```
## Créditos
[Nextcloud](https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html#nextcloud-in-the-webroot-of-nginx)
[Mozilla](https://ssl-config.mozilla.org/#server=nginx&version=1.20.1&config=modern&openssl=3.0.7&guideline=5.7)
[KumbiaPHP](https://github.com/KumbiaPHP/Documentation/blob/master/es/to-install.md#configurar-nginx)
[Computingforgeeks](https://computingforgeeks.com/install-php-8-on-rocky-linux-almalinux-8/?expand_article=1)
[Nginx](https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi)