server { listen 80; listen [::]:80; server_name example.com www.example.com; root /var/www/example.com/public; index index.php index.html index.htm; access_log /var/log/nginx/example.com/access.log; error_log /var/log/nginx/example.com/error.log; location / { try_files $uri $uri/ /index.php; } location ~ ^/wp-json/ { rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last; } location ~* /wp-sitemap.*\.xml { try_files $uri $uri/ /index.php$is_args$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; client_max_body_size 20M; location = /50x.html { root /usr/share/nginx/html; } # Config PHP-FPM connection location ~ \.php$ { # Map to appropriate php-fpm sock version fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } # Enable gzip compression gzip on; gzip_vary on; gzip_min_length 1000; gzip_comp_level 5; gzip_types application/json text/css application/x-javascript application/javascript image/svg+xml; gzip_proxied any; # Long browser cache lifetime can speed up repeat visits to your page location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ { access_log off; log_not_found off; # Set cache to 30d, but you can set to 'max' if necessary # expires max; expires 30d; } # Disable access to hidden files location ~ /\.ht { access_log off; log_not_found off; deny all; } }