Page 1 of 1

can not start NodeJS applications with SLL

Posted: Sat Jun 29, 2019 9:12 am
by anxieter
I can not run my application on Ubuntu VPS with VestaCP.

I started with pm2 my application on the server on port 3000.

Before that, I made some preparations:

1) Installed let's encrypt certificates

2) Applied force-https template so that ngnix redirects me from HTTP

VestaCP generated 2 ngnix configs - my-site.com.nginx.ssl.conf and my-site.com.nginx.conf

When I run my site on my-site.com - there is 403 error

The decision is quite easy - I should change

Code: Select all

proxy_pass  https://10.223.41.249:8443;
to

Code: Select all

proxy_pass  https://10.223.41.249:3000;
Then restart nginx

Code: Select all

 service nginx restart
But in this case, I have 500 error. And I really confused about setting...

These are configs:

Note that 10.223.41.249 is my server internal IP. I suppose given by Vesta.

Code: Select all

# my-site.com.nginx.conf
server {
    listen      10.223.41.249:80;
    server_name my-site.come www.my-site.com;
    location / {
        rewrite ^(.*) https://my-site.com$1 permanent;
    }
include /home/admin/conf/web/*nginx.my-site.com.conf_letsencrypt;
}

Code: Select all

# my-site.com.nginx.ssl.conf
server {
    listen      10.223.41.249:443;
    server_name my-site.com www.my-site.com;
    ssl         on;
    ssl_certificate      /home/admin/conf/web/ssl.my-site.com.pem;
    ssl_certificate_key  /home/admin/conf/web/ssl.my-site.com.key;
    error_log  /var/log/apache2/domains/my-site.com.error.log error;

    location / {
        proxy_pass      https://10.223.41.249:3000;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|e$
            root           /home/admin/web/my-site.com/public_html;
            access_log     /var/log/apache2/domains/my-site.log combined;
            access_log     /var/log/apache2/domains/my-site.site.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/admin/web/my-site.com/document_errors/;
    }

    location @fallback {
        proxy_pass      https://10.223.41.249:3000;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/admin/conf/web/*nginx.my-site.com.conf_letsencrypt;
    include /home/admin/conf/web/snginx.my-site.com.conf*;
}
My network activity is

Code: Select all

root@46:/home/admin/conf/web# sudo netstat -ltunp | grep 80
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      7804/mongod
tcp        0      0 10.223.41.249:80        0.0.0.0:*               LISTEN      6225/nginx: master
tcp        0      0 10.223.41.249:8080      0.0.0.0:*               LISTEN      2778/apache2
tcp        0      0 127.0.0.1:8081          0.0.0.0:*               LISTEN      2778/apache2
tcp        0      0 0.0.0.0:8083            0.0.0.0:*               LISTEN      26350/nginx: master
tcp        0      0 127.0.0.1:8084          0.0.0.0:*               LISTEN      6225/nginx: master
root@46:/home/admin/conf/web# sudo netstat -ltunp | grep 443
tcp        0      0 10.223.41.249:443       0.0.0.0:*               LISTEN      6225/nginx: master
tcp        0      0 10.223.41.249:8443      0.0.0.0:*               LISTEN      2778/apache2
root@46:/home/admin/conf/web# sudo netstat -ltunp | grep 8443
tcp        0      0 10.223.41.249:8443      0.0.0.0:*               LISTEN      2778/apache2
root@46:/home/admin/conf/web# sudo netstat -ltunp | grep 3000
tcp6       0      0 :::3000                 :::*                    LISTEN      2146/node
root@46:/home/admin/conf/web#
Hope, this would help

There is also a config in my app. I'm not sure but I suspect this too

Code: Select all

module.exports = {
  'process.env.BASE_URL': prod
    ? 'https://my-site.com'
    : 'http://localhost:3000'
};

Re: can not start NodeJS applications with SLL

Posted: Sat Jun 29, 2019 9:15 pm
by Alex Connor
Tell me, is this some kind of complete script or did you write it yourself? If this is a complete script, you need to see the documentation.

Re: can not start NodeJS applications with SLL

Posted: Sun Jun 30, 2019 11:17 am
by anxieter
Thanks for reply.
The `complete script` - is it about the code of my app, or nginx config?
Nginx config I presented was just genegated from .tpl and .stpl files that are inside VestaCP bundle - i can not write it myself.

Re: can not start NodeJS applications with SLL

Posted: Sun Jun 30, 2019 7:57 pm
by Alex Connor
anxieter wrote:
Sun Jun 30, 2019 11:17 am
The `complete script` - is it about the code of my app, or nginx config?
About app. Maybe you use some CMS or other NodeJS app?

Re: can not start NodeJS applications with SLL

Posted: Sun Jul 07, 2019 9:08 am
by anxieter
The app uses next.js framework. But I almost shure that it doesn't affect to nginx because it works as usual node.js application.
I just run express server from pm2 command running on 3000 port.

Re: can not start NodeJS applications with SLL

Posted: Sun Jul 07, 2019 9:46 am
by Alex Connor

Re: can not start NodeJS applications with SLL

Posted: Tue Jul 09, 2019 6:57 pm
by anxieter
Documetation tells that I should remove try_files and set some headers... I also removed file types.

Please, check If my nginx config is correct. I'm totally new to all that stuff.
Server returns 500 in this way too -(...

Code: Select all

server {                                                                                                                                                                  
    listen      10.223.41.249:443 ssl;                                                                                                                                    
    server_name my.site www.my.site;                                                                                                                 
    # ssl         on;                                                                                                                                                     
    ssl_certificate      /home/admin/conf/web/ssl.my.site.pem;                                                                                                     
    ssl_certificate_key  /home/admin/conf/web/ssl.my.site.key;                                                                                                     
    error_log  /var/log/apache2/domains/my.site.error.log error;                                                                                                   
                                                                                                                                                                          
    location / {                                                                                                                                                          
            proxy_pass      https://10.223.41.249:3000;                                                                                                                       
            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;                                                                              
    }                                                                                                                                                                     
                                                                                                                                                                          
    location /error/ {                                                                                                                                                    
        alias   /home/admin/web/my.site/document_errors/;                                                                                                          
     }                                                                                                                                                                    
                                                                                                                                                                          
    location @fallback {                                                                                                                                                  
        proxy_pass      https://10.223.41.249:3000;                                                                                                                       
    }                                                                                                                                                                     
                                                                                                                                                                          
    location ~ /\.ht    {return 404;}                                                                                                                                     
    location ~ /\.svn/  {return 404;}                                                                                                                                     
    location ~ /\.git/  {return 404;}                                                                                                                                     
    location ~ /\.hg/   {return 404;}                                                                                                                                     
    location ~ /\.bzr/  {return 404;}                                                                                                                                     
                                                                                                                                                                          
    include /home/admin/conf/web/*nginx.my.site.conf_letsencrypt;                                                                                                  
    include /home/admin/conf/web/snginx.my.site.conf*;                                                                                                             
}                                                                                                                                                                         

Code: Select all

nginx -t 
and

Code: Select all

 sudo service nginx restart
are made...