2

I'm setting up a webapps using Node JS + React + NGINX on AWS and then when i want to access the url /auth

it return me some HTML code instead of JSON like i wanted to be i tested the code on LOCALHOST and it works fine

I tried to set the folder permission, because i think maybe user permission is the problem

I also tried editing some stuff on the Nginx.conf

below is my app.conf for the nginx

upstream webapp{
    server 127.0.0.1:3018;
}

server_names_hash_bucket_size 64;
server_names_hash_max_size 512;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name 127.0.0.1;
        server_name_in_redirect off; 

    if ($http_x_forwarded_proto = 'http'){
       return 301 https://$host$request_uri;
    }


   location / {
        root /home/website/client/build;
        try_files $uri /index.html;
        log_not_found off;
        access_log off;
    }

    #error_page  405     =200 $uri;

    if ( $http_user_agent ~* (nmap|nikto|wikto|sf|sqlmap|bsqlbf|w3af|acunetix|havij|appscan) ) {
        return 403;
    }
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block;";
    add_header Strict-Transport-Security "max-age=2592000; includeSubDomains" always;
}
action     {…}
​
payload: Object { isAuth: false, error: true }
​
type: "auth_member"

i expect the output code like this one but instead the web give me something else

2
  • at which port the node server is running, the current Nginx configurations does not proxy your API requests to the node server, can you clarify more? Oct 23, 2019 at 11:44
  • The node server running at port 3018 as i stated above at the upstream
    – Gregory
    Oct 27, 2019 at 18:03

1 Answer 1

1

you have to define the upstrem location to be proxed to:

 # this is an example you can modify the path on as you get it
 location /api {
       proxy_pass http://webapp;
       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;
    }


6
  • hello thanks for the reply unfortunately is i change the proxy_pass to be "webapp" like u said it returns me with error 502 BAD GATEWAY i already define the upstream name "webapp" pointing to "server 127.0.0.1:3018"
    – Gregory
    Oct 23, 2019 at 12:58
  • Did you check that the app running on port 3018? Oct 23, 2019 at 13:24
  • can you send an example request path to the 127.0.0.1:3018?,locally if you like Oct 23, 2019 at 13:30
  • The Server indeed running on port 3018 since Locally, i can try the webapp perfectly fine with no issue
    – Gregory
    Oct 23, 2019 at 13:46
  • you see, the /api location must match you request path format ex. exampl.com/api nginx will catch that and proxy it to the port 3018 if the path was not starting with the trailing /api Nginx will serve the default server Oct 23, 2019 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.