admin管理员组文章数量:1297028
I have the following nginx configuration to serve blog on /blog/
URL.
server {
listen 80;
server_name example.in www.example.in;
root /var/www/website;
index index.html index.htm index.php;
# Serve blog
location /blog {
return 301 /blog/;
}
location /blog/ {
autoindex on;
alias /var/www/blog/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
# Serve other files
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
The homepage is working fine at and also the admin panel is working perfectly
/
When the blog posts permalink is set to plain, the blogs posts are opening fine with the URL
/?p=123
But on changing the permalink to another format blog/blog/2021/04/16/sample-post/
, It is giving 404
/
I have the following nginx configuration to serve blog on /blog/
URL.
server {
listen 80;
server_name example.in www.example.in;
root /var/www/website;
index index.html index.htm index.php;
# Serve blog
location /blog {
return 301 /blog/;
}
location /blog/ {
autoindex on;
alias /var/www/blog/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
# Serve other files
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
The homepage is working fine at https://example.in/blog
and also the admin panel is working perfectly https://example.in/blog/wp-admin/
When the blog posts permalink is set to plain, the blogs posts are opening fine with the URL
https://example.in/blog/?p=123
But on changing the permalink to another format blog/blog/2021/04/16/sample-post/
, It is giving 404
https://example.in/blog/blog/2021/04/16/sample-post/
Share
Improve this question
edited Apr 17, 2021 at 1:45
Anuj TBE
asked Apr 16, 2021 at 13:56
Anuj TBEAnuj TBE
1135 bronze badges
0
1 Answer
Reset to default 1You should use the ^~
prefix on the location
statement, change the alias
statement to root /var/www;
, and change the last parameter of the try_files
statement.
For example:
location ^~ /blog/ {
autoindex on;
root /var/www;
index index.php;
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
本文标签: Wordpress blog posts permalinks giving 404 on nginx
版权声明:本文标题:Wordpress blog posts permalinks giving 404 on nginx 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741611231a2388271.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论