GNU/Linux >> Belajar Linux >  >> Linux

Wordpress - Mengubah permalink memberi saya 404 kesalahan di nginx

Saya menggunakan wordpress multisite dengan pengaturan permalink khusus:/%category%/%postname%/

/etc/nginx/site-available/domain.conf

Di server{

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

Jika root wordpress Anda bukan webroot tetapi http://domain.com/wordpress/:

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

Jika Anda menggunakan wordpress lama dengan blogs.dir, tambahkan:location ^~ /blogs.dir {internal;alias /var/www/wordpress/wp-content/blogs.dir;access_log off; log_not_found off; kedaluwarsa maks;}

Periksa konfigurasi nginx:sudo nginx -t

Muat ulang nginx:layanan sudo nginx memuat ulang

Coba juga ubah pengaturan permalink.


Itu adalah Apache .htaccess tulis ulang aturan, tetapi Anda telah menyatakan bahwa Anda berada di server Nginx. Nginx tidak menggunakan .htaccess -seperti file level direktori, apalagi menggunakan .htaccess file itu sendiri.. Anda perlu mengedit konfigurasi server itu sendiri. Codex memiliki contoh detail:

# 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;
}

Harus menambahkan potongan kode ini ke /sites-available/your-settings-file dan /sites-enabled/your-settings-file :

server {
[...]

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

[...]
}

Ini bekerja untuk saya sekarang.


Linux
  1. Cara Menginstal WordPress Menggunakan Nginx di Ubuntu 18.04

  2. Instal WordPress di Nginx Ubuntu

  3. Cara membuat Permalink WordPress berfungsi di Nginx

  1. nginx - 413 Permintaan Entitas Terlalu Besar

  2. Host WordPress di Ubuntu 20.04, Mysql 8, Ubuntu 20.04, Nginx

  3. Kesalahan pemasangan plugin WordPress

  1. Ubuntu 20.04:WordPress dengan instalasi Nginx

  2. Instal WordPress dengan Docker Compose, Nginx, Apache dengan SSL

  3. getpwnam(www) gagal di /etc/nginx/nginx.conf