sgtaziz / WebMessage

A client for communicating with the WebMessage tweak on iOS. Send and receive messages from the comfort of your computer
72 stars 12 forks source link

Proper setup for port forwarding through Nginx? #108

Open EricAndrechek opened 3 years ago

EricAndrechek commented 3 years ago

Hi there! Just wanted to say I am loving your tweak!!

If I were to want to run this tweak on an old iOS device with a terrible battery laying around at home, and wanted to access my texts on my computer remotely, is there a way for me to port forward this over the internet? I have tried setting up Nginx on my home server to just proxy_pass my iOS WebMessage server, but it doesn't seem to be working. Thanks!

sgtaziz commented 3 years ago

It should work. Here is an example for setting it up with an SSL certificate:

server {

    listen 8180; # This can be any port available on your home server. Does not have to be the WM port.
    server_name webmessage.domain.com; # If you need to use a domain, set it here. 

    # Here you define your SSL certificates. 
    # I highly recommend setting this up if you're going to open the connection over the web.
    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;

    # Some more settings to setup SSL
    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    location / {
      # Here you can set headers. Its usually good practice to allow the proxy to be as real as possible.
      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;

      # This is required to enable WebSockets to work
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      # This is where you will specify your WebMessage server.
      # If it doesn't work, you can try disabling SSL from WebMessage, and use nginx' SSL config.
      # If you disable SSL, make sure to change https to http.
      proxy_pass          https://192.168.1.10:8180;
      proxy_read_timeout  90;

      # This is not required, but can be helpful in some cases. Ensure http(s) matches your config above.
      proxy_redirect      https://192.168.1.10:8180 https://webmessage.domain.com;
    }
  }

I have not tested this, but feel free to try it out and let me know how it works. I'll keep this ticket open until we can get it figured out for you 👍

sgtaziz commented 3 years ago

@EricAndrechek Have you had the chance to test this? If it's all good, I'll go ahead and close this issue

EricAndrechek commented 3 years ago

Sorry for the late reply, I've been poking around at it and trying to get things working but without much success. Here is what I've got so far:

So, to recap:

Let me know what other error messages or debug logs I can get to you!

sgtaziz commented 3 years ago

If you will be using SSL on your proxy, you really don't need SSL on the tweak itself. Though the authorization pass in the GET request can pose a security risk, which is something I overlooked.

For the root of the problem, I want to focus on the client device will only connect if it has SSL turned on. SSL on your tweak should be disabled if using a proxy is your goal, so I'm glad you got that down! As far as testing, I think it would be better to test through a browser (same IP/port into your browser, https/http respectively) If http does not work, then your SSL is on. This definitely has something to do with your nginx setup if that's the case, so would be ideal to check that.

For the 501 error, that is definitely an nginx-related issue again. Sounds like nginx isn't able to accept the blob data. Unfortunately it is currently difficult for me to setup a proxy to help test; however, I will try to update you as soon as I am able to give it a go!