LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2017, 03:23 PM   #1
E-Kami
Member
 
Registered: Jul 2012
Posts: 56

Rep: Reputation: Disabled
Can't get reverse proxy working


I'm trying to use nginx as a proxy for this nodejs app. What I've done so far is running the nodejs app with npm --start on localhost:2791 with a bs-config.json which looks like this:

Code:
    {
      "port": 2791,
      "server": {
          "baseDir": "src",
          "routes": {
              "/node_modules": "node_modules"
          }
       }
    }
As for my nginx configuration it looks like this:

Code:
    server {
        listen 80;
        server_name demo.example.com;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    
        location /angular {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header HOST $http_host;
                proxy_set_header X-NginX-Proxy true;
    
                proxy_pass http://127.0.0.1:2791;
                proxy_redirect off;
       }
    }
When I access to demo.example.com/angular I get a:

Code:
    [1] 17.06.10 18:35:51 304 GET /index.html
Which is great so far but this same page depends on other js files and when it tries to open them it can't find them so I get errors such as:

Code:
    [error] 18#18: *1 open() "/etc/nginx/html/node_modules/dc/dc.css" failed (2: No such file or directory), client: 81.64.208.179, server: demo.example.com, request: "GET /node_modules/dc/dc.css HTTP/1.1", host: "demo.example.com", referrer: "http://demo.example.com/angular/"
    [error] 18#18: *3 open() "/etc/nginx/html/node_modules/core-js/client/shim.min.js" failed (2: No such file or directory), client: 81.64.208.179, server: demo.example.com, request: "GET /node_modules/core-js/client/shim.min.js HTTP/1.1", host: "demo.example.com", referrer: "http://demo.example.com/angular/"
    [error] 21#21: *4 open() "/etc/nginx/html/browser-sync/browser-sync-client.js" failed (2: No such file or directory), client: 81.64.208.179, server: demo.example.com, request: "GET /browser-sync/browser-sync-client.js?v=2.18.8 HTTP/1.1", host: "demo.example.com", referrer: "http://demo.example.com/angular/"
How can I tell nginx, instead of trying to find the files in /etc/nginx/html to pass the requests to the node app running on 127.0.0.1:2791? I tried to add root /home/user/quickstart_ng2d3/src in my config file but it didn't work as the sources/dependencies are spread into multiples folders of the project and are linked together with the help of the node configuration files. Thanks for your help!

Last edited by E-Kami; 06-10-2017 at 03:27 PM.
 
Old 06-11-2017, 03:17 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

Quote:
How can I tell nginx, instead of trying to find the files in /etc/nginx/html to pass the requests to the node app running on 127.0.0.1:2791?
Add the trailing slash at the location URI and see if it helps:
Code:
 location /angular/ {
Regards
 
Old 06-11-2017, 04:55 AM   #3
E-Kami
Member
 
Registered: Jul 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
Hi,


Add the trailing slash at the location URI and see if it helps:
Code:
 location /angular/ {
Regards
Hello, I actually solved it by just using location /. Looks like if I want to use location /angular/ I will have to modify the html tag in index.html but I don't want to touch the project source file. Thank for your help
 
Old 06-11-2017, 07:47 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Cool!
You may mark the thread as solved from the "Thread Tools" on top of the page

Cheers
 
  


Reply

Tags
nginx, node.js



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
squid reverse proxy through https, no cache, no public proxy? alanford Linux - Software 1 02-08-2016 10:55 AM
Nginx Reverse proxy on a internal apache reverse server ITiger Linux - Software 0 04-25-2014 07:44 AM
reverse proxy (HTTP) mapping not working properly noir911 Linux - Server 4 07-28-2009 07:25 AM
Squid 2.6 Reverse Proxy from Squid(3128) to OrginServer(80) Not working rraj Linux - Server 0 06-06-2008 02:29 PM
Reverse proxy (apache) causing ASP.net web apps to stop working linuxmandrake Linux - Server 0 05-29-2008 05:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration