Cuando montas un sitio web por tu cuenta en tu propio equipo o en un servidor VPS, necesitas un software que se encargue de gestionar las peticiones y el tráfico entre los clientes y el propio sitio web. Principalmente en el mundo PHP, lo puedes hacer con Apache o con Nginx.
Personalmente me gusta más Nginx xa que lo veo algo más "moderno" y simple que apache (evitando tener que gestionar y modifcar ficheros XML por ejemplo)
Aquí te dejo un plantilla estándar para montar tu sitio Drupal. Ojo!, recuerda que es genérica y que no he metido nada de caché ni SSL que te lo diré en siguientes posts :D
server {
server_name ${TU_NOMBRE_DE_DOMINIO}
root ${TU_RUTA_HASTA_LA_WEB}/web;
index index.html;
# Tamaño máximo de cada petición
client_max_body_size 64M;
access_log /var/log/nginx/${TU_NOMBRE_DE_DOMINIO}_access.log;
error_log /var/log/nginx/${TU_NOMBRE_DE_DOMINIO}_error.log;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Very rarely should these ever be accessed outside of your lan
location ~* \.(txt|log)$ {
allow 192.168.0.0/16;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
location ~ ^/sites/.*/private/ {
return 403;
}
# Block access to scripts in site files directory
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
# Permitir el acceso para lets-ncrypt
location ~* ^/.well-known/ {
allow all;
}
# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}
location / {
try_files $uri /index.php?$query_string; # For Drupal >= 7
# Si quieres habilitar un basic_auth en el sitio
#auth_basic "Control de acceso";
#auth_basic_user_file /etc/nginx/.htpasswd;
}
location @rewrite {
rewrite ^ /index.php; # For Drupal >= 7
}
# Don't allow direct access to PHP files in the vendor directory.
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
# Protect files and directories from prying eyes.
location ~* \.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|/(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config)$|/#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$ {
deny all;
return 404;
}
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
# Ensure the php file exists. Mitigates CVE-2019-11043
try_files $fastcgi_script_name =404;
include fastcgi_params;
# Block httpoxy attacks. See https://httpoxy.org/.
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
# PHP socket location.
fastcgi_pass unix:/run/php/christianlr-fpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
# Fighting with Styles? This little gem is amazing.
location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
try_files $uri @rewrite;
}
# Handle private files through Drupal. Private file's path can come with a language prefix.
location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
try_files $uri /index.php?$query_string;
}
# Enforce clean URLs
# Removes index.php from urls like www.example.com/index.php/my-page --> www.example.com/my-page
# Could be done with 301 for permanent or other redirect codes.
if ($request_uri ~* "^(.*/)index\.php/(.*)") {
return 307 $1$2;
}
listen 80;
}