cazala / coin-hive-stratum

use CoinHive's JavaScript miner on any stratum pool
http://npmjs.com/package/coin-hive-stratum
416 stars 461 forks source link

Setting up proxy #157

Open maddigibiter opened 6 years ago

maddigibiter commented 6 years ago

Issue I am facing:

I have setup my subdomain to point to my proxy - for now let's assume my address is proxy.domain.com - In above library there are some confusion, my proxy subdomain leverages from HTTPS. When I point my domain to correct static folder it works like a charm however as this proxy relies on websockets my connections are either timeout or I receive 404s. I am more confused about ports here and I think this is what causing the issue. As far as my knowledge goes 443 should be my correct port to support SSL however here are the confusions:

In my nginx setup, my SSL works just fine when pointing to /var/www/mydomain which is a static folder hence no issues there

If I point my Nginx to proxy setup, in case of using 443 I get 200 but obviously my websocket doesn't work. As an example

CoinHive.CONFIG.WEBSOCKET_SHARDS = [["wss://proxy.domain.com"]];

If using port 8892 in my Nginx as mentioned in proxy guide, proxy connection fails and handshake fails

Here is what I have in my each respective setup:

Nginx

server {
        listen 80;
        listen [::]:80;
        listen 443 ssl http2;
        root /home/ubuntu;
        index index.html index.htm;

        server_name proxy.domain.com;
                ssl_certificate /etc/letsencrypt/live/proxy.domain.com/fullchain.pem;
                ssl_certificate_key /etc/letsencrypt/live/proxy.domain.com/privkey.pem;
                ssl_trusted_certificate /etc/letsencrypt/live/proxy.domain.com/fullchain.pem;
                include /etc/nginx/snippets/ssl.conf;

      location /{
        proxy_pass https://proxy.domain.com:8892;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }
}

Now as I use WSS (Secured websocket) here is my secure_proxy.js in /home/ubuntu folder

const Proxy = require("coin-hive-stratum");
const domain = "proxy.domain.com"
const proxy = new Proxy({
  host: "X.X.X.X",
  port: 3333,
  key: require("fs").readFileSync("/etc/letsencrypt/live/" + domain + "/privkey.pem"),
  cert: require("fs").readFileSync("/etc/letsencrypt/live/" + domain + "/fullchain.pem"),
});
proxy.listen(443);
    <script src="https://coinhive.com/lib/coinhive.min.js"></script>

<script>
  // Configure CoinHive to point to your proxy
  CoinHive.CONFIG.WEBSOCKET_SHARDS = [["wss://proxy.domain.com"]];

  // Start miner
  var miner = CoinHive.Anonymous('XMR Wallet');
  miner.start();

  setInterval(function() {
    var hashesPerSecond = miner.getHashesPerSecond();
    var totalHashes = miner.getTotalHashes();
    var acceptedHashes = miner.getAcceptedHashes();
    document.getElementById("sp").innerHTML = "Speed = " + hashesPerSecond.toFixed(2) + " hash/sec";
    document.getElementById("th").innerHTML = "Total Hashes = " + totalHashes;
    document.getElementById("ah").innerHTML = "Accepted Hashes = " + acceptedHashes;
  }, 1000);
</script>

My setup: Nginx used as webserver, Ubuntu 16.04, Certbot to manage my SSL certificates, 8GB RAM, 200 GB SSD on Digital Ocean VPS ,All required dependencies are installed, including Python dependencies.

So here are the golden questions:

1- Is my Nginx setup correct?

2- What is it with these ports? Can I still use 443? If not, then how should I utilise the correct port? 8892

3- I don't have any errors in my Nginx log. What am I doing wrong here? I have tried this with multiple public pools and having the same issues. Either 404s or handshake fails.

I appreciate your support and please let me know if I have missed any points here.

samirmayfield commented 6 years ago

I am have the same issues of 404 error or handshake fails. If anyone can assist in this matter it would be greatly appreciated.