Showing posts with label proxy. Show all posts
Showing posts with label proxy. Show all posts

Sep 30, 2022

Customized a Node.js App in Multipass

This is a short tutorial to:

  • Create an Ubuntu VM with cloud-init file
  • Install a running Node.js app with a Nginx as the front-end proxy


Cloud-init is a widely used approach to customize a Linux VM as it boots for the first time. It can be used to install packages and write files, or to configure users and security hardening. 

Cloud-init also works across distributions which means it automatically uses the native package management tool for the distro you select.

#cloud-config
package_upgrade: true
packages:
  - nginx
  - nodejs
  - npm
write_files:
  - owner: www-data:www-data
    path: /etc/nginx/sites-available/default
    content: |
      server {
        listen 80;
        location / {
          proxy_pass http://localhost:3000;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection keep-alive;
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
        }
      }
  - owner: webadm:webadm
    path: /home/webadm/myapp/index.js
    content: |
      var express = require('express')
      var app = express()
      var os = require('os');
      app.get('/', function (req, res) {
        res.send('Hello World from host ' + os.hostname() + '!')
      })
      app.listen(3000, function () {
        console.log('Hello world app listening on port 3000!')
      })
runcmd:
  - service nginx restart
  - cd "/home/webadm/myapp"
  - npm init
  - npm install express -y
  - nodejs index.js


Save the YAML as webadmin.yaml and then start creating the VM with Multipass as below:

multipass -n nodejs3k --cloud-init webadmin.yaml

multipass info nodejs3k

Last, open the URL to http://nodejs3k_ip_addr with your browser.


Links:

Feb 21, 2022

Transparent Proxy Using Squid Cache and Cisco Router in Linux

There is a excellent article about setting up transparent proxy to control web traffic using Squid and Cisco router. Here's my summary note.


Step 1: Install Squid Cache

 

Step 2: Prepare Squid Cache

$ sudo vi /etc/sysctl.conf

# To make sure the OS will never drop the packet because of wrong dest IP addr.

net.ipv4.ip_forward = 1 #set to 1 for enable the packet forwarding feature

# To make sure the OS will accept packets that not accessible or the dest IP addr in the same subnet
net.ipv4.conf.default.rp_filter = 0 # set to 0 for disable the reverse path filter behavior

$

Step 3: Create GRE interface

$ vi /etc/sysconfig/network-script/ifcfg-gre0

DEVICE=gre0
BOOTPROTO=static
IPADDR=10.0.0.2         #unused ip address in your network
NETMASK=255.255.255.252
ONBOOT=yes
IPV6INIT=no

$ sudo service network restart

$

Step 4: Configuring Squid Cache

$ vi /etc/squid/squid.conf

http_port 3128 intercept                 # Define SQUID listening port
wccp2_router 192.168.1.254          #ip address of the router
wccp2_forwarding_method gre
wccp2_return_method gre
wccp2_service standard 0

$ service squid restart

$ sudo  iptables -t nat -A PREROUTING -i gre0 -p tcp --dport 80 -j REDIRECT --to-port 3128
$ sudo  iptables -t nat -A POSTROUTING -j MASQUERADE

Step 5: Cisco router configuration

Enable WCCP at Cisco router

R1(config)# ip wccp version 2
Then we must use an ACL for introducing SQUID cache machine to router
R1(config)# ip access-list standard SQUID-MACHINE
R1(config-std-nacl)# permit host 192.168.1.10

Define ACL to except squid-cache from WCCP tunnel. Then forward web traffic to squid-cache via WCCP tunnel.

R1(config)#ip access-list LAN-TRAFFICS
R1(config-ext-nacl)#deny ip host 192.168.1.10 any                            #Prevent SQUID to get in loop
R1(config-ext-nacl)#permit tcp 192.168.1.0 0.0.0.255 any equal www           #define LAN Traffics

Next, create ACL with WCCP:

R1(config)# ip wccp web-cache redirect-list LAN-TRAFFIC group-list SQUID-MACHINE

Last, specific the interface for web traffic re-direction:

R1(config)#interface fastEthernet 0/0
R1((config-if)# ip wccp web-cache redirect in


Link:

Nov 27, 2021

Abhinavsingh Proxy.py

Do you need a lightweight proxy server that support HTTP/HTTPS/HTTP2/WebSockets, to facilitate end-to-end testing?

Here's a stripped-down version of lightweight proxy server (written in Python).

 

Summary:

  • Fast and scalable and lightweight
  • Programmable (with plugins)
  • Real time dashboard
  • Supports: HTTP (1.0, 1.1, 2.0), HTTPS and websockets
  • IPv4 and IPv6 support
  • Basic authentication support

 

Links:

May 5, 2011

Windows Update Error 80240030

When you get the Windows Update error code 80240030, then you are most likely having issue with:

  • Can't update your windows. Windows Update fails.
  • Can't access your proxy setting in MSIE. IE crashes once you click the "LAN setting".
  • IE can't access Internet (thru proxy).
I'm having all these issues since I upgrade to IE9. And here I find the solution to fix/repair  the 80240030 error for me:
  1. Open command prompt (with Administrator mode).
  2. Type "netsh winhttp reset proxy"
  3. Type "net stop wuauserv"
  4. Type "net start wuauserv"
It does works in Windows 7 (32-bit & 64-bit) too. Enjoy!