设置wordpress使用域名直接访问(不加/wordpress/)的方法
2022-07-29 10:13:20
221
{{single.collect_count}}

前言

使用wordpress官方的安装手册,安装完后,默认访问都是需要在域名后加/wordpress/的
很麻烦,特别是作为个人站,就觉得很丑不能忍。设置方法如下:

一,修改仪表盘设置

仪表盘——>设置——>常规——>WordPress地址(URL) 和 站点地址(URL)
都改成你的域名
点击 保存
然后在浏览器输入你的域名,回车,结果

404 file not found!

当然了,设置还没完成呢

二,修改Nginx配置文件

命令:
vim /etc/nginx/nginx.conf

第一步 修改 root 路径

使其直接指向wordpress:
root /var/www/html/wordpress;
修改好后应该是这样的:

server {listen 80;server_name你的域名;root /var/www/html/wordpress;indexindex.html index.htm index.php default.php default.html;location ~ \.php$ {root /var/www/html/wordpress;fastcgi_pass 127.0.0.1:9000;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}

重载nginx配置文件:
nginx -s reload

第二步 解决phpmyadmin 不能访问的问题

(提示:如果你未使用phpmyadmin 管理mysql数据库,此步骤可忽略)
由于server路径改变,自然导致phpmyadmin 不能访问

方法一,新建server,重新指定路径和端口
server { listen 新的端口号(例如666); server_name 你的域名; root /var/www/html; location / { index index.php index.html index.htm default.php default.htm default.html;} location ~ \.php$ {fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }

这个方法的好处:更改默认的80端口,一定程度防范数据库被攻击。
重载nginx配置文件使生效。

方法二 把整个phpmyadmin文件夹移动到wordpress内。

有问题欢迎留言讨论。。

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}