wordpress拒绝访问_Nginx + Wordpress页面或帖子URL返回拒绝访问

本文档详细记录了在Nginx服务器上遇到WordPress页面或帖子URL返回拒绝访问的问题,并通过调整Nginx配置文件,特别是正确使用`root`和`alias`指令,以及设置`try_files`解决了问题。主要改动包括取消别名部分的注释,明确`try_files`的路径,以及在特定location中添加`try_files`指令。
摘要由CSDN通过智能技术生成

谢谢你的答案@ r3wt。但是,我猜上面的配置文件是不合适的我不想保持原样(但是对于我来说开发似乎没问题,因为部署我宁愿为每个站点使用单独的配置文件)。

所以,别名部分和我的问题应该正确定义try_files因为我想要捕获链接以localhost / szpetra开头所以我添加它并取消注释别名部分因为现在我清楚地了解root和别名whis之间的区别是什么是:

This will result in files being searched for in /foo/bar/bar as the full URI is appended.

location /bar {

root /foo/bar;

}

This will result in files being searched for in /foo/bar as only the URI part after /bar is appended.

location /bar {

alias /foo/bar;

}

资料来源:https://forum.nginx.org/read.php?2,129656,130107

现在修改后的配置文件如下所示:

server {

listen 80;

server_name localhost;

access_log /var/log/nginx/localhost-access_log main;

error_log /var/log/nginx/localhost-error_log info;

root /var/www/localhost/htdocs/;

index index.php index.html index.htm; # I used index definition here so I think I shouldn't define it under a 'location' field.

location ~ \.php$ {

try_files $uri =404;

include /etc/nginx/fastcgi.conf;

fastcgi_pass unix:run/php-fpm.socket;

}

location /phpmyadmin {

alias /var/www/localhost/htdocs/phpmyadmin;

access_log /var/log/nginx/phpmyadmin-access_log main;

error_log /var/log/nginx/phpmyadmin-error_log info;

}

location /samplewordpress {

alias /var/www/localhost/htdocs/samplewordpress;

access_log /var/log/nginx/samplewordpress-access_log main;

error_log /var/log/nginx/samplewordpress-error_log info;

}

location /szpetra {

# alias /var/www/localhost/htdocs/szpetra; #uncommenting alias helped me solve the problem

access_log /var/log/nginx/szpetra-access_log main;

error_log /var/log/nginx/szpetra-error_log info;

# index index.php index.html index.htm; # this doesn't need cause I defined the indexes above in the server{} section but I'm not sure that about this

try_files $uri $uri/ /szpetra/index.php?$args; # Adding this line helped me solve the problem

}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值