Wordpress on AWS EC2 - broken after assigning elastic IP

半世苍凉 提交于 2020-12-29 13:10:43

问题


So, I got Wordpress installed and working just fine. I can access the site and the wp-admin via the public DNS that I get from the instance.

However, once I create an elastic IP and associate it with the instance, I can no longer access wp-admin and the home page style sheets and JavaScript files are not loaded.

I am attempting to access the site and the wp-admin using the new public IP from the elastic IP. Same thing is true if I try to use the public DNS from either the elastic IP or the EC2 instance.

When I view the page source I see that the reason things aren't loaded is because the URL for all of the assets (.css, .js. etc,) is pointing to the bold public DNS

When I disassociate the elastic IP things do not go back to working again.

I'm missing something but don't know what.

Any help would be appreciated


回答1:


Your wordpress admin is already associated with your publicDNS. This is because, when you have logged-in the wp-admin console, you have created a new admin user. This information with respect to your publicDNS was saved in the mysql db. So you won't be able to access wp-admin from the elastic IP.

What you can do ?

You can log-in to your wordpress mysql and update all the references of the publicDNS to Elastic IP. Once it is done, you will be able to access the wp-admin from the static IP.




回答2:


I run into the same problem. A quick fix is to hardcode your site URL into the wp-config.php which you can edit via FTP.

define('WP_HOME','http://yoursite.com'); 
define('WP_SITEURL','http://yoursite.com');

Worked fine for me.

See also https://codex.wordpress.org/Changing_The_Site_URL for guideline.




回答3:


I too faced the same issue, followed the steps in this page to get my issue fixed.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/hosting-wordpress.html

Follow steps under this section: "Help! My Public DNS Name Changed and now my Blog is Broken"

Pasting it here for quick reference: Login via ssh to your ec2 instance then run the below commands:

  1. Download the wp-cli with the following command

    curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

  2. Search and replace the old site URL in your WordPress installation with the following command. Substitute the old and new site URLs for your EC2 instance and the path to your WordPress installation (usually /var/www/html or /var/www/html/blog)

    php wp-cli.phar search-replace 'old_site_url' 'new_site_url' --path=/path/to/wordpress/installation --skip-columns=guid



来源:https://stackoverflow.com/questions/19697007/wordpress-on-aws-ec2-broken-after-assigning-elastic-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!