Access Antlets

Access Antlets Locally

Good News!

As of antsleOS 0.3.2, you don’t need to configure nginx to access your web services anymore!

How It Works

Becoming a super hero is a fairly straight forward process:

If you setup an antsle.us subdomain in antHill, you can use the antlet name with your subdomain

antlet_name.subdomain.antsle.us

In either case, the antlet must have a web server installed and listening on port 80 (http), else you may get a '502 Bad Gateway' error.

See the SSL (https) page for https access to an antlet.

Access antlets by Domain Name

If you want to configure Antsle so that the world can access your antlets by domain name, e.g. myawesomesite.com, then this page will guide you through the steps to do that.

Before you start, you need to setup port forwarding in your router. That step is only needed once. You don’t need to do that for every new domain name and/or antlet. You can skip port forwarding altogether if you (a) only access antlets from your local LAN/WiFi or (b) you’re using a tunnelling solution.

After you’ve setup port forwarding (once), it’s a three-step process:

  1. Get a domain name.

  2. Set the A record.

  3. Connect domain with antlet.

Here are our instructions for each of these steps:

Get a domain name

You can register your domain name, e.g. mysite.com, through any domain registrar of your liking, e.g. godaddy.com.

Set the A record

Set the A record of your new domain to the public IP address of your home or office Internet connection. To check your IP address, just go to checkip.dyndns.org in your browser. Copy that IP address to your clipboard. The go to the portal of the registrar that you bought your domain from. In case you bought it from GoDaddy, see here for help.

Go to “DNS settings” and find where to set the A record. Set it to the IP address that you found out earlier.

After you’ve changed the A record, please allow up to 48 hours to let that change propagate through all DNS server of the Internet. In many cases you will be able to use the new domain after two hours or so. It’s a good idea to restart your router a few hours after you’ve updated the A record, so that the router will pull the latest DNS information from the Internet.

Please keep in mind that this step works best when you have a static IP address from your ISP. Alternatively, you can use a dynamic DNS provider.

HTTP Access with Domain Name

After steps 1 and 2 are done, any traffic for your domain will arrive in your router. The port forwarding in your router will send it onwards to your Antsle - forward ports 80 and 443 to the private IP address of the Antsle (displayed in antMan). The last step now is to tell the Antsle to connect the domain name to the antlet of your choice. In order to achieve that, follow these steps:

Login to your Antsle via ssh [email protected]_name.local.

Enter this command: cd /etc/nginx/virtualhosts.

Then enter this command: nano mysite.com.conf. Use your domain name, not mysite.com!

Paste this text into the file:

server {
server_name www.mysite.com;
rewrite ^ $scheme://mysite.com$request_uri redirect;
}
server {
listen 80;
server_name mysite.com;
root /var/www;
location / {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Ssl off;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://10.1.1.10;
}
}

Make sure to replace mysite.com with the your own domain name, and replace 10.1.1.10 with the IP address of the antlet you want to connect this domain name to.

The intent of the first 'server { ... }' block is to redirect URLs prefixed with www to a URL without it, e.g. 'www.mysite.com' will redirect to 'mysite.com'. Many people always type a 'www' in the URL but is not part of many domain names.

If your domain name is prefixed with www or you are using some other subdomain like yoyo.mysite.com, you can delete the first 'server { ... }' block

server {
server_name www.mysite.com;
rewrite ^ $scheme://mysite.com$request_uri redirect;
}

and edit the second 'server { ... }' block with the full domain name.

server {
listen 80;
server_name yoyo.mysite.com;
root /var/www;
location / {
proxy_read_timeout 300;
...
}
}

Press Ctrl-X in nano, enter Y for Yes when asked if you want to save, and hit Enter for the file name.

Finally, enter this command: service nginx restart

You’re ready to go now. From anywhere in the world, mysite.com will lead you directly to your antlet now.

HTTPS Access with Domain Name

To set up an ssl certificate for an antlet we have a couple of options

  • Install the certificate in the antlet

  • Use nginx proxy to handle the certificate

The first option requires the antlet to have a bridged NIC and be addressed directly. The traffic for each antlet/webserver would require a unique public IP address or use a unique port number for the router to direct the traffic to the correct antlet IP address. Here the certificate files are installed and handled by the antlet

The second option allows nginx to connect to the proper antlet based on the URL in the header of the request. This is desireable because you can forward traffic (at the router) for multiple sites to one IP address, the private IP address of the Antsle. The certificate files are installed and handled by nginx on the edgeLinux OS.

First create a directory for your certificate files on the edgeLinux OS.

mkdir -p /etc/ssl/certs/mycerts

Use SCP or SFTP to copy your certificate files to this directory.

Create and edit a new nginx virtualhosts configuration file for your domain name. Replace example.com with your domain name.

nano /etc/nginx/virtualhosts/ssl.example.com.conf

Paste the following content into the file and replace 'example.com' with your domain name.

# SSL to antlet
# If you want to use your domain example.com in HTTPS mode (with SSL),
# rename this file to ssl.example.com.conf (from ssl.example.com.conf.HTTPS)
# Replace example.com with your domain name.
# Make sure you have your SSL certificate installed properly.
# The certificate files are not required to be in the directories presented here, but
# the path must be the correct path to your certificate files.
# The webserver on your antlet will listen on port 80 (http).
# Nginx on edgeLinux handles SSL (https).
# Redirect http://www.example.com to https://example.com
# If your domain name does include 'www' then remove this server block and use the full
# domain name in the last server block.
server {
listen 80;
server_name www.example.com;
rewrite ^ https://example.com$request_uri redirect;
}
# Redirect http://... to https://...
server {
listen 80;
server_name example.com;
rewrite ^ https://example.com$request_uri redirect;
}
# Redirect https://www... to https://example.com
# If your domain name does include 'www' then remove this server block and use the full
# domain name in the last server block.
server {
listen 443 ssl;
ssl_certificate /etc/ssl/certs/mycerts/example.com.crt;
ssl_certificate_key /etc/ssl/certs/mycerts/example.com.key;
server_name www.example.com;
rewrite ^ $scheme://example.com$request_uri redirect;
}
# Think of the word 'example' in 'upstream example' as a variable name which is
# used in other server blocks. This name must be unique among all your .conf
# files. It is used in the two 'proxy_pass' lines in the next server block.
# If you change the upstream variable name then be sure to update the proxy_pass
# lines also.
upstream example {
# Enter the IP address and port number of your antlet handling this domain
server 10.1.1.10:80;
}
server {
listen 443 ssl;
ssl_certificate /etc/ssl/certs/mycerts/example.com.crt;
ssl_certificate_key /etc/ssl/certs/mycerts/example.com.key;
server_name example.com;
root /var/www;
location / {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_buffers 4 256k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 256k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Ssl off;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_pass http://example;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf|woff|woff2)(\?.*)?$ {
expires 365d;
add_header Cache-Control "public, max-age=315360000";
access_log off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_buffers 8 24k;
proxy_buffer_size 2k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Ssl off;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Frame-Options SAMEORIGIN;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_pass http://example;
}
}

Restart the nginx service

service nginx restart