Cómo tener múltiples sitios Wordpress con Nginx, PHP y MySQL
Tags: MySQL, Nginx, WordPress, PHP, Seguridad Informatica

En Nginx, lo que hay que hacer, es configurar cada virtual host por separado. Por ello, normalmente se utiliza el directorio sites-enabled y demás. Personalmente no me gusta, prefiero usar el conf.d pero esto queda a su gusto…

En este archivo de VHost les paso uno que les hará la vida más fácil y les explico un poco, es un poco largo así que prepárense…

fastcgi_cache_path /var/cache/nginx/misitio levels=1:2 keys_zone=MISITIO:500m inactive=5m;

limit_req_zone $binary_remote_addr zone=MISITIOLIMIT:10m rate=2r/s;



listen 80;

server_tokens off;

server_name misitio.com;

return 301

} server {listen 80;server_tokens off;server_name misitio.com;return 301 https://$server_name$request_uri

server {

server_name misitio.com;

ssl_certificate /etc/nginx/ssl/misitio.pem;

ssl_certificate_key /etc/nginx/ssl/misitio.key;

listen 443 ssl http2;

server_tokens off;

fastcgi_cache_key "$scheme$request_method$host$request_uri";

fastcgi_hide_header X-Powered-By;

fastcgi_cache_use_stale error timeout invalid_header http_500;

proxy_hide_header X-Powered-By;



add_header Referrer-Policy "no-referrer-when-downgrade";

add_header X-Frame-Options SAMEORIGIN;

add_header Strict-Transport-Security "max-age=31536000";

add_header X-Content-Type-Options nosniff;

add_header X-XSS-Protection "1; mode=block";

set $no_cache 0;

if ($request_method = POST) {

set $no_cache 1;

}

if ($query_string != "") {

set $no_cache 1;

}

if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {

set $no_cache 1;

}

if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {

set $no_cache 1;

}



root /var/www/html/misitio;

index index.php index.html index.htm;



client_max_body_size 100M;

location / {

if ($request_method = 'OPTIONS') {

add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';

add_header 'Access-Control-Max-Age' 1728000;

add_header 'Content-Type' 'text/plain; charset=utf-8';

add_header 'Content-Length' 0;

return 204;

}

try_files $uri $uri/ /index.php$is_args$args;

}



location ~ \.php$ {

fastcgi_read_timeout 60;

proxy_read_timeout 60;

fastcgi_buffers 128 4096k;

fastcgi_buffer_size 4096k;

fastcgi_index index.php;

fastcgi_pass unix:/run/php/php7.4-fpm-misitio.sock;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

fastcgi_send_timeout 60;

fastcgi_cache_bypass $no_cache;

fastcgi_no_cache $no_cache;

fastcgi_cache_valid 200 301 302 5m;

fastcgi_cache MISITIO;

fastcgi_busy_buffers_size 4096k;

fastcgi_temp_file_write_size 4096k;

}

location = /xmlrpc.php {

deny all;

access_log off;

log_not_found off;

}



location ~ /\.ht {

deny all;

}



location ~ /\.stub {

deny all;

}



location ~* wp-config.php {

deny all;

access_log off;

log_not_found off;

}

location ~ /\. {

deny all;

return 404;

}

location ~* (webpack.dev.js|webpack.prod.js|Browserslist|LICENCE|package.json|package-lock.json|deploy.sh) {

deny all;

return 404;

}



location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {

expires 7d;

etag on;

add_header Pragma public;

add_header Cache-Control "public";

if_modified_since exact;

log_not_found off;

access_log off;

}



location = /favicon.ico {

log_not_found off;

access_log off;

}



location = /robots.txt {

allow all;

log_not_found off;

access_log off;

}



location ~* /manifest.json{

allow all;

log_not_found off;

access_log off;

}

location ~* /(?:uploads|files|wp-content|wp-includes|akismet)/.*.php$ {

deny all;

access_log off;

log_not_found off;

}

location ~ /\.(svn|git)/* {

deny all;

access_log off;

log_not_found off;

}

location ~ /\.user.ini {

deny all;

access_log off;

log_not_found off;

}

location ~ \wp-login.php$ {

limit_req zone=MISITIOLIMIT;

}

}