EC2 上的 Fedora + Nginx + Wordpress 虚拟主机生成指向实际主机名的链接

EC2 上的 Fedora + Nginx + Wordpress 虚拟主机生成指向实际主机名的链接

我目前正在尝试在 Nginx 中设置虚拟主机,以便我可以像在不同的域中一样运行 wordpress 服务器。我目前遇到的问题是,当我转到“http://example-domain.com/blog/',每个链接都指向亚马逊主机,'ec2----*.compute-1.amazonaws.com”。我希望所有这些链接都使用“example-domain.com”主机进行解析。

我的主要 Nginx conf 文件(nginx.conf)是:

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_names_hash_bucket_size 64;

    log_format  main  '$remote_addr - $remote_user [$time_local] $request '
                  '"$status" $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  2;

    #gzip  on;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    #
    # The default server
    #
    server {
    listen       80;
    server_name  _;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/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;
    }
    }
}

虚拟主机设置了以下配置:

server {
    listen      80;
    server_name example-domain.com;

    root   /var/www/example-domain.com/html;
    index  index.html index.htm index.php;

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO $fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

wordpress 文件夹位于 /var/www/example-domain.com/html/blog/。有人知道为什么首页上的所有 wordpress 链接都使用 ec2 主机名而不是虚拟主机配置中定义的主机名吗?如果知道,请帮帮我。

提前致谢!

答案1

这是因为 wordpress 在数据库设置中保存了 URL/域名。您需要登录 wordpress wp-admin 并更新站点 URL,或者直接在数据库中更新。

相关内容