2

I learned about Nginx yesterday and to be more accurate I learned for the first time all the topics covered on the following urls:

But I'm still here...stuck,

Where I am


I'm editing this Nginx config file: /etc/nginx/sites-available/default

server {
        listen 80 default_server;
        listen [::]:80 default_server;


        root /var/www/html;

        server_name mysite.mydomain.com;
        ssl_dhparam /etc/ssl/certs/dhparam.pem;

        location / {
                proxy_pass http://localhost:8080;
                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;
        }

    listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
}

My Goal


  1. To have two nodejs http(s??) servers listening on 2 local ports
  2. Reverse-proxy them to two https ports
  3. Profit

So to transform this:

http://localhost:8080/ & http://localhost:8181

To this

https://mysite.domain.com/ & https://mysite.domain.com:1337/

Basically I'm trying to setup a parse server alongside with a node webapp and I don't want the paths to collide so I want them on different public ports.

Sample node webapp server:

const app = express();

app.use(compression());
app.use(express.static(path.resolve(__dirname, '../dist')));
app.get('*', function(req, res) {
  res.sendFile(path.resolve(__dirname, '../dist/index.html'));
});


app.listen(8181);

Thanks, in advance.

elios264
  • 121
  • 1
  • 3
  • You don't have to show the list of the docs you've read :-) But you can include their relevant parts. For example, if the doc says X, you do X, and it doesn't happen as you wanted. Then refer the doc URL, and cite the X part. And also cite your config (that you did well). – peterh Aug 12 '17 at 00:17
  • Btw, I mostly track with `strace`, what requests the node server exactly gets. They are very useful, because both the nginx and also the express have funny "surprises" about their path handling. It is useful if you can test the node server by direct http queries. I hope you get a more detailed answer (this was only a comment). – peterh Aug 12 '17 at 00:19
  • 2
    You need to add two separate `server` blocks (virtual hosts) in nginx, where you configure the different domains / ports for SSL, and then you add the respective `proxy_pass` to each one. – Tero Kilkanen Aug 12 '17 at 08:54
  • 1
    @TeroKilkanen Make that an answer :) – Zenexer Aug 12 '17 at 09:12

0 Answers0