简体   繁体   中英

Nginx resverse proxy for prams in an expressjs application

I have got a route in expressjs application with the following code.

...

router.get("/:id", async (req, res, next) => {
        try {
          // debug(`The req  is ${req.params.id}`);
          const data = await getSuperHerors(req.params.id);
          res.send(data);
        } catch (err) {
          next(err);
        }
      });

...

I want to setup my nginx revere proxy to forward on the id. The conf file for nginx is here... server { root /var/www/html;

    server_name example.biz; # managed by Certbot
    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://127.0.0.1:3000;

            # proxy_pass http://127.0.0.1:3000/$1$is_args$args;

            # set $upstream http://localhost:3000;
            # proxy_pass $upstream/$1$is_args$args;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.biz/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/example.biz/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf; 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
}

server {
    if ($host = example.biz) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 ;
        listen [::]:80 ;
    server_name example.biz;
    return 404; # managed by CertbotWhat is wrong with my reverse proxy file.

}

... What is wrong with my reverse proxy file. For now I have put it back to its original but I have tried to use the configs behind the comments.

Joseph Shanahan

Thanks, you are right all requests were forwarded. I went back and had a look at my setup and found something else wrong. Cheers Joseph Shanahan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM