Answer the question
In order to leave comments, you need to log in
Is it possible to access the lxc container from the Internet?
Hello. I have one fat server, and I constantly do something on it. For yourself, for others, for educational purposes or for some other reason. And the idea came up so that I would not kill the server with all sorts of different specific software, to raise a virtual machine for each task. The choice fell on the LXC. It seems not difficult. I installed it on an experimental server, and ran Ubuntu inside lxc in a couple of commands.
Everything is fine, Ubuntu starts up inside, there is Internet inside the Ubuntu container, packages are installed. Everything seems to be great. But how can I make sure that I can enter the container using a direct ip? So that you don’t have to enter the server first, and then enter the container from under the terminal. Is it possible to do so?
Well, the same question, can I place a couple of sites inside containers? In the classical form, everything is simple. I buy a domain, I make an A record on the ip of the server, and going through the domain, my requests will go to the server itself. Is it possible to do the same magic with lxc? The entire Google is inundated with posts from the 2016s, in which, on the contrary, they are at war with Internet access from under the container. It already works for me out of the box.
Answer the question
In order to leave comments, you need to log in
Is it possible to do so?
Well, the same question, can I place a couple of sites inside containers?
how to make it so that I can enter the container by direct ip?
export WAN_IP="91.1.1.2"
export LXC_IP="10.1.1.1"
export FORWARD_PORT="443"
iptables -A FORWARD -d $LXC_IP -j ACCEPT
iptables -t nat -A PREROUTING -d $WAN_IP -p tcp -m tcp --dport $FORWARD_PORT -j DNAT --to-destination $LXC_IP:$FORWARD_PORT
Well, the same question, can I place a couple of sites inside containers?
server {
listen 80;
server_name mysite.example.com;
location /.well-known/acme-challenge/ {
access_log off;
default_type "text/plain";
}
return 301 https://$host$request_uri;
}
server {
listen 443 ssl; # managed by Certbot;
server_name mysite.example.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
ssl on;
ssl_certificate /etc/letsencrypt/live/mysite.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://10.1.1.1:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question