Skip to content

Instantly share code, notes, and snippets.

@ARCHTKT
Created August 1, 2021 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ARCHTKT/c3bcd6c961ea16116a9934f798153d5a to your computer and use it in GitHub Desktop.
Save ARCHTKT/c3bcd6c961ea16116a9934f798153d5a to your computer and use it in GitHub Desktop.
server {
# El puerto por el que se accede, por defecto el 443
listen 443 ssl http2;
listen [::]:443 ssl http2;
# El dominio al cual tiene que responder
server_name dominio.com;
# Dónde están alojados los archivos
root [RUTA A CARPETA]/dominio.com/public;
# Dónde están los certificados del certificado SSL
ssl_certificate /etc/letsencrypt/live/dominio.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dominio.com/privkey.pem;
# Archivo que se usa como índice
index index.php index.html;
# Crea un log específico para este sitio web
access_log [RUTA A CARPETA]/dominio.com/logs/access.log;
error_log [RUTA A CARPETA]/dominio.com/logs/error.log;
# Incluye la configuración por defecto
include global/server/defaults.conf;
# Incluye reglas generales SSL
include global/server/ssl.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Lo que hace Nginx cuando se solicita un PHP
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
# Redireccción de http a https
server {
listen 80;
listen [::]:80;
server_name dominio.com www.dominio.com;
return 301 https://dominio.com$request_uri;
}
# Redireccción de dominio con www a sin www
server {
listen 443;
listen [::]:443;
server_name www.dominio.com;
ssl_certificate /etc/letsencrypt/live/dominio.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dominio.com/privkey.pem;
return 301 https://dominio.com$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment