Apache: Wordpress over local network

2019-01-29 04:55发布

问题:

I have an Apache webserver on a Ubuntu VM from which I want to run a Wordpress intranet site that can only be accessed from the internal network. The site works fine from localhost on the server obviously.

The server's local ip is 192.168.1.93, and when I go to http://192.168.1.93/wordpress from another computer it loads a text-only page, with no themes or images.

Then when I click on a link, it goes to localhost/wordpress/whatever which obviously doesn't work from another computer.

There seem to be two issues here: one is that Apache/Wordpress doesn't seem to work across a network, the second is that Wordpress seems to show all the links to localhost.

Is there anything I'm missing?

回答1:

In your wp-config.php, set the following constants:

define('WP_SITEURL', 'http://192.168.1.93/wordpress');
define('WP_HOME', 'http://192.168.1.93/wordpress');

When you serve your wordpress site from your local computer, all theme related files are probably served from localhost or 127.0.0.1, which are addresses which always point to "the local computer". So, when you access the website from another computer, it tries to fetch the CSS files and images from the other computer and not from the serving one.

By setting the before mentioned constants, you force Wordpress to serve the files from the given IP address.

Please remember to remove those constants from the wp-config.php file when you deploy your website to an actual server.