using nginx streams

· ahwx's blog

using nginx streams to forward connections from a vps to your own server and thus hiding your ip address

# Using a VPS as a proxy server for HTTP and SSH.

I am aware that this post is a little rough, I'm not sorry.

Requirements/ingredients:

# Obtaining a vps

# Installing nginx

1su -
2apt update && apt -y upgrade
3apt -y install nginx nginx-common libnginx-mod-stream # latter one should not be needed but I install it anyways

# Configuring nginx

1cd /etc/nginx && mkdir rproxy && cd rproxy && mkdir stream stream/available stream/enabled
2nvim stream/available/ssh.conf

Add the following content:

1upstream ssh {
2  server home-server-ip:22;
3}
4
5server {
6  listen 22;
7  proxy_pass ssh;
8}

# nginx.conf

1cd /etc/nginx && nvim nginx.conf

Now change the following content:

1  include /etc/nginx/conf.d/*.conf;
2  # include /etc/nginx/sites-enabled/*;
3  include /etc/nginx/rproxy/http/enabled/*.conf;
4}
5
6stream {
7  include /etc/nginx/rproxy/streams/enabled/*.conf;
8}

# So now, the Virtual Host section should look like this

1# Virtual Host Configs
2  include /etc/nginx/conf.d/*.conf;
3  # include /etc/nginx/sites-enabled/*;
4  include /etc/nginx/rproxy/http/enabled/*.conf;
5}
6
7stream {
8  include /etc/nginx/rproxy/streams/enabled/*.conf;
9}

# activating our configurations

1ln -s /etc/nginx/rproxy/http/available/*.conf /etc/nginx/rproxy/http/enabled
2ln -s /etc/nginx/rproxy/stream/available/*.conf /etc/nginx/rproxy/stream/enabled

Let's test if everything is correct:

nginx -t

# Restart nginx

1systemctl restart nginx

# And you're done!