GNU/Linux >> Tutoriales Linux >  >> Linux

Wordpress:cambiar los enlaces permanentes me da errores 404 en nginx

Estoy usando wordpress multisitio con una configuración personalizada de enlaces permanentes:/%category%/%postname%/

/etc/nginx/sitio-disponible/dominio.conf

En el servidor{

location / {
    try_files $uri $uri/ /index.php?q=$uri$args;
}

Si su wordpress raíz no es webroot sino http://domain.com/wordpress/:

location /wordpress/ {
    try_files $uri $uri/ /wordpress/index.php?q=$uri$args;
}

Si está utilizando wordpress antiguo con blogs.dir, agregue:ubicación ^~ /blogs.dir {internal;alias /var/www/wordpress/wp-content/blogs.dir;access_log off; log_not_found apagado; caduca como máximo;

Compruebe la configuración de nginx:sudo nginx -t

Recargar nginx:sudo service nginx reload

Prueba también a cambiar la configuración del enlace permanente.


Esos son Apache .htaccess reescriba las reglas, pero ha declarado que está en un servidor Nginx. Nginx no usa un .htaccess -como archivo de nivel de directorio, mucho menos usa el .htaccess archivo en sí mismo. Necesita editar la configuración del servidor en sí. El Codex tiene una muestra detallada:

# WordPress single blog rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
    try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)

    include fastcgi.conf;
    fastcgi_index index.php;
#   fastcgi_intercept_errors on;
    fastcgi_pass php;
}

Tuve que agregar este fragmento de código a ambos /sites-available/your-settings-file y /sites-enabled/your-settings-file :

server {
[...]

if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
}

[...]
}

Me está funcionando ahora.


Linux
  1. Cómo instalar WordPress usando Nginx en Ubuntu 18.04

  2. Instalar WordPress en Nginx Ubuntu

  3. Aloja WordPress en Ubuntu 20.04, Mysql 8, Ubuntu 20.04, Nginx

  4. Instalar WordPress con Docker Compose, Nginx, Apache con SSL

  5. getpwnam(www) falló en /etc/nginx/nginx.conf

Cómo bloquear XML-RPC en WordPress usando Nginx/Apache

Cómo bloquear el acceso a wp-admin y wp-login en Nginx/Apache

Cómo cambiar el puerto de WordPress en Apache y Nginx

¿Obtener 404 On Lamp Permalinks (usando WordPress)?

Instalar WordPress con Nginx en Ubuntu 18.04

Cómo instalar WordPress en una pila Nginx LEMP usando Ubuntu 14.04