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:
-
Any VPS or server which has portforwarding options for the ports you will need.
-
NGINX on the vps.
-
Some service on another server that you will proxy to.
-
Some technical knowledge.
Obtaining a vps #
- You can get a vps from Amazon AWS for free for 12 months (1 core, 1GB ram and 8GB disk is more than enough. I'm currently using about 120MB of RAM).
- You can get a generic vps from Linode or Vultr or any other hosting provider.
- You can use a free vps from Oracle.
- You can use any other server, just make sure that it fits the requirements.
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