How to Point a Domain to LXC using NGINX in Host

If you have a website or a web application in a LXC, you need a way to let people access it. We can do it by assigning a domain to the LXC.

This requires NGINX to be installed in your host server.

Imagine the static IP of your LXC is (See Assign Static Internal IP Addresses to LXC.) and you need to assign the domain to that LXC.

Navigate to /etc/nginx/sites-available in your host server, and create a new virtual host file like the following. Name the file with the Reverse Domain Name Notation of the domain you intend to use. As we’re going to use as the domain, the Reverse Domain Name Notation of that is com.budhajeewa, so you need to name the virtual host file as com.budhajeewa.conf.

Put the following content into that file:

server {
 listen 80;

 location / {
  proxy_set_header Host $host;

Things you may need to change are colored in red.

Once this virtual host file is created, you need to enable it by creating a symlink to this file in /etc/nginx/sites-enabled. So, cd into that directory, and issue the following command:

ln -s ../sites-available/com.budhajeewa.conf

Once that’s done, you need to restart NGINX by issuing service nginx restart command.

Above configuration assumes that the web server in your LXC runs on port 80 (; if it’s not, change accordingly.

Once this is done, NGINX will listen to the port 80 of your host server and see if the requests are coming for the domain If they are, NGINX will accept the request and forward it to the port 80 of the LXC which has the internal IP address

Leave a Reply