Hello, What i want to achieve is like this
www.domain.com - HTML website www.domain.com/blog - wordpress
i want to have wordpress on separate virtual host. What will be the nginx configuration in this case.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Ok, I am assuming by “i want to have wordpress on separate virtual host” you mean you will host it on a separate server ( a virtualhost in this context is an apache configuration to support a different subdomain or domain and it sounds like that’s not what you’re trying to configure).
For this lets use:
server1.example.org (The site where example.org will be pointed and the server hosting your static web content)
server2.example.org (The server that will host your WordPress blog) - We will assume that WordPress is already up and running here.
example.org (the domain that will be used for both).
You’ll want to use a plan Ubuntu droplet for server 1 and you can use the WordPress one-click image for the second if you like.
Point your domain name to server1’s IP address in your DNS configuration for this domain.
On server 1, install nginx
Now you can upload your static html site to
/usr/share/nginx/html
and the site should be viewable by browsing to your droplet’s IP address.Next we will set up a proxy configuration in nginx so that everything for /blog is proxied to your WordPress droplet.
Open the file /etc/nginx/sites-enabled/default and edit it so it looks like this:
Save these changes and restart nginx with:
Now you’ll want to access your WordPress droplet directly by it’s IP address and log into wp-admin. In settings, change the base_url settings to http://example.org/blog
Now you should be able to view your static site at http://example.org and your wordpress blog at http://example.org/blog
Ok, I am assuming by “i want to have wordpress on separate virtual host” you mean you will host it on a separate server ( a virtualhost in this context is an apache configuration to support a different subdomain or domain and it sounds like that’s not what you’re trying to configure).
For this lets use:
server1.example.org (The site where example.org will be pointed and the server hosting your static web content)
server2.example.org (The server that will host your WordPress blog) - We will assume that WordPress is already up and running here.
example.org (the domain that will be used for both).
You’ll want to use a plan Ubuntu droplet for server 1 and you can use the WordPress one-click image for the second if you like.
Point your domain name to server1’s IP address in your DNS configuration for this domain.
On server 1, install nginx
Now you can upload your static html site to
/usr/share/nginx/html
and the site should be viewable by browsing to your droplet’s IP address.Next we will set up a proxy configuration in nginx so that everything for /blog is proxied to your WordPress droplet.
Open the file /etc/nginx/sites-enabled/default and edit it so it looks like this:
Save these changes and restart nginx with:
Now you’ll want to access your WordPress droplet directly by it’s IP address and log into wp-admin. In settings, change the base_url settings to http://example.org/blog
Now you should be able to view your static site at http://example.org and your wordpress blog at http://example.org/blog
Hi @ryanpq ,
Thanks for this answer, it helped me a lot. I still have a problem though: my website is initially loaded over https, so when I proxy_pass to http://wordpress droplet’s IP/ at /blog location , my content (JS + CSS) cannot load.
And if I proxy_pass to https://wordpress droplet’s IP/, I get a 502 BAD GATEWAY.
How can I do to fix this? And in Wordpress admin, my website URL should be http://example.org/blog or https://example.org/blog?
Thanks a lot!