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 10.0.3.2
(See Assign Static Internal IP Addresses to LXC.) and you need to assign the domain budhajeewa.com
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 budhajeewa.com
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; server_name budhajeewa.com; location / { proxy_pass http://10.0.3.2:80; 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 (http://10.0.3.2: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 budhajeewa.com
. If they are, NGINX will accept the request and forward it to the port 80 of the LXC which has the internal IP address 10.0.3.2
.