1.在目录:/etc/nginx/conf.d/ 新建一个配置文件 wp.conf,内容如下:
server {
listen 80;
server_name www.ttt.top; //域名
server_name_in_redirect off;
location /wordpress {
proxy_set_header Host $host;
proxy_pass http://HttpdServer/wordpress; #HttpdServer 为自定义的配置,也可以替换为IP+端口
}
location / {
rewrite ^/(.*)$ http://www.luoy.top/wordpress;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
HttpdServer内容为:
upstream HttpdServer{
server localhost:82 max_fails=10 fail_timeout=10s;
keepalive 64;
}
2.重启nginx:systemctl restart nginx
3.更换域名后,需要修改wp数据库中旧的访问地址
UPDATE wp_options SET option_value = replace(option_value, '旧域名','新域名') ;
UPDATE wp_posts SET post_content = replace(post_content, '旧域名','新域名') ;
UPDATE wp_comments SET comment_content = replace(comment_content, '旧域名','新域名') ;
UPDATE wp_comments SET comment_author_url = replace(comment_author_url, '旧域名','新域名') ;
4.更换域名可以下载插件,在后台管理界面的工具菜单,选择【更换域名】: