A
A
Artem R2018-04-12 22:52:07
linux
Artem R, 2018-04-12 22:52:07

Can't configure nginx proxy server, how to do it right?

How to set up a proxy server on nginx (for an https request) so that data is transmitted to the node.js server on port 3000, and receive a response from node.js and output to the user?
Now I did this, but the result seems to be zero:
nginx.conf

server {
        # IP, который мы будем слушать
        listen       443 ssl;
        server_name  mysite.ru;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        
        keepalive_timeout    60;
        ssl_certificate            __тут адрес до сертификата__/mysite.ru.crt;
        ssl_certificate_key     __тут адрес до сертификата__/mysite.ru.key;
        ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers                "HIGH:!RC4:!aNULL:!MD5:!kEDH";
        add_header                Strict-Transport-Security 'max-age=604800';

        location / {
            # IP и порт, на которых висит node.js
            proxy_pass                 http://127.0.0.1:3000/;
            proxy_redirect         off;
            proxy_set_header    X-Real-IP $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header    Host $http_host;
            proxy_pass_header  Set-Cookie;
        }
    }

node.js
var http = require('http');

http.createServer(function (req, res) {
    console.log('Test');
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(3000);

console.log('Server running at port 3000');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Zubkov, 2018-04-13
@zubkov_work

If it's worth it, then try changing the config, add the server's IP address to the listen line to get something like
listen 8.8.8.8:443 ssl;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question