Localtunnel: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 8: Line 8:
| valign="top" |
| valign="top" |
<source lang="bash">
<source lang="bash">
cat << EOF | sudo tee /etc/systemd/system/academia-lt.service >>/dev/null
cat << EOF | sudo tee /etc/systemd/system/chorke-academia-lt.service >>/dev/null
[Unit]
[Unit]
Description=Academia Localtunnel Daemon
Description=Academia Localtunnel Daemon
Line 17: Line 17:
Type=simple
Type=simple
Restart=on-failure
Restart=on-failure
ExecStart=lt -p 80 -s academia-chorke
ExecStart=lt -p 80 -s chorke-academia
TimeoutStopSec=20
TimeoutStopSec=20
KillMode=process
KillMode=process
Line 32: Line 32:




sudo systemctl enable  --now academia-lt
sudo systemctl enable  --now chorke-academia-lt
     systemctl status  academia-lt
     systemctl status  chorke-academia-lt




sudo systemctl disable --now academia-lt
sudo systemctl disable --now chorke-academia-lt
     systemctl status  academia-lt
     systemctl status  chorke-academia-lt




sudo systemctl restart academia-lt
sudo systemctl restart chorke-academia-lt
     systemctl status  academia-lt
     systemctl status  chorke-academia-lt




sudo systemctl stop    academia-lt
sudo systemctl stop    chorke-academia-lt
     systemctl status  academia-lt
     systemctl status  chorke-academia-lt
</source>
</source>


Line 54: Line 54:
| valign="top" colspan="2" |
| valign="top" colspan="2" |
<source lang="bash">
<source lang="bash">
cat << EOF | sudo tee /etc/nginx/sites-enabled/academia-chorke.loca.lt >>/dev/null
# nginx virtual host & reverse proxy config
cat << EOF | sudo tee /etc/nginx/sites-enabled/chorke-academia.loca.lt >>/dev/null
server {
server {
   listen 2015;
   listen 2015;
Line 61: Line 62:
   index index.html;
   index index.html;
   root /var/www/html;
   root /var/www/html;
   server_name academia-chorke.loca.lt;
   server_name chorke-academia.loca.lt;


   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Line 77: Line 78:
   }
   }


   access_log /var/log/nginx/academia-chorke.loca.lt/access.log;
   access_log /var/log/nginx/chorke-academia.loca.lt/access.log;
   error_log  /var/log/nginx/academia-chorke.loca.lt/error.log info;
   error_log  /var/log/nginx/chorke-academia.loca.lt/error.log info;


   error_page 500 502 503 504 /500.html;
   error_page 500 502 503 504 /500.html;
Line 86: Line 87:


EOF
EOF
</source>
|-
| colspan="2" |
----
|-
| valign="top" colspan="2" |
<source lang="bash">
# haproxy frontend and backend config
: <<'EOC'
frontend chorke
  bind *:80
  mode http
  acl host-is-chorke-academia    hdr(host) -i chorke-academia.loca.lt
  use_backend chorke-academia    if host-is-chorke-academia
backend chorke-academia
  server apache 127.0.0.1:2015
  mode http
EOC
</source>
</source>


Line 95: Line 117:
  '''Note:'''
  '''Note:'''
  No need to update any '''/etc/hosts''' entries  
  No need to update any '''/etc/hosts''' entries  
  open https://academia-chorke.loca.lt  &>/dev/null &
  open https://chorke-academia.loca.lt  &>/dev/null &
  open https://loca.lt/mytunnelpassword &>/dev/null &
  open https://loca.lt/mytunnelpassword &>/dev/null &
  open https://ipv4.icanhazip.com      &>/dev/null &
  open https://ipv4.icanhazip.com      &>/dev/null &

Revision as of 18:54, 25 January 2024

source ~/.nvm/nvm.sh && nvm use node
npm install -g localtunnel

Linux Service

cat << EOF | sudo tee /etc/systemd/system/chorke-academia-lt.service >>/dev/null
[Unit]
Description=Academia Localtunnel Daemon
After=syslog.target network.target

[Service]
User=${USER}
Type=simple
Restart=on-failure
ExecStart=lt -p 80 -s chorke-academia
TimeoutStopSec=20
KillMode=process

[Install]
WantedBy=multi-user.target

EOF
sudo systemctl daemon-reload


sudo systemctl enable  --now chorke-academia-lt
     systemctl status  chorke-academia-lt


sudo systemctl disable --now chorke-academia-lt
     systemctl status  chorke-academia-lt


sudo systemctl restart chorke-academia-lt
     systemctl status  chorke-academia-lt


sudo systemctl stop    chorke-academia-lt
     systemctl status  chorke-academia-lt

# nginx virtual host & reverse proxy config
cat << EOF | sudo tee /etc/nginx/sites-enabled/chorke-academia.loca.lt >>/dev/null
server {
  listen 2015;
  listen [::]:2015;

  index index.html;
  root /var/www/html;
  server_name chorke-academia.loca.lt;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_set_header Host $http_host;
  proxy_redirect off;

  location / {
    proxy_pass http://127.0.0.1:3001;
    try_files $uri $uri/ =404;
  }
  
  location /api {
    proxy_pass http://127.0.0.1:3002;
  }

  access_log /var/log/nginx/chorke-academia.loca.lt/access.log;
  error_log  /var/log/nginx/chorke-academia.loca.lt/error.log info;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 25M;
  keepalive_timeout 10;
}

EOF

# haproxy frontend and backend config
: <<'EOC'
frontend chorke
   bind *:80
   mode http
   acl host-is-chorke-academia    hdr(host) -i chorke-academia.loca.lt
   use_backend chorke-academia    if host-is-chorke-academia

backend chorke-academia
   server apache 127.0.0.1:2015
   mode http

EOC

Note:
No need to update any /etc/hosts entries 
open https://chorke-academia.loca.lt  &>/dev/null &
open https://loca.lt/mytunnelpassword &>/dev/null &
open https://ipv4.icanhazip.com       &>/dev/null &

Playground

lt --host 127.0.0.1 --port 80 --subdomain academia-chorke
lt --port 80 --subdomain academia-chorke
lt -h 127.0.0.1 -p 80 -s academia-chorke
lt -p 80 -s academia-chorke

curl -k https://loca.lt/mytunnelpassword
curl -k https://ipv4.icanhazip.com
sudo nginx -t
sudo rm /etc/systemd/system/academia-lt.service
systemctl daemon-reload
systemctl reset-failed

References