node.js - nginx nodejs express reverse proxy issue
阿神
阿神 2017-06-05 11:11:29
0
1
618

1. I have a nodejs program, developed using express. In the local test environment, I directly use express to do static resources and route forwarding
2. Now it is moved to the production environment, and nginx is used as a reverse proxy to be responsible for static resource

question:

Question 1. After configuring, I found that the static resources were all 404, and then I added

to the nginx configuration file.
 location ~ \.(css)$ {
        expires 2d;
    root /app/www/nodejs-blog-demo/public;
    }
    location ~ \.(js)$ {
        expires 2d;
    root /app/www/nodejs-blog-demo/public;
    }

After that, at least I can access static resources, but if my static resources are multi-level directories, such matching rules will be very complicated. How do you deal with it?

Question 2. My nginx is equipped with a reverse proxy like this, 3000 is nodejs, but now the processing/ directory can be accessed, but my /admin/aaa path prompts 404

    location / {
        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;
    }

I think it may be caused by the routing processing I did with nodejs, but I don’t know how to solve it

My nodejs routing is as follows

module.exports = function (app) {
  app.use('/admin', router);
}

router.get('/aaa', auth.requireLogin, function (req, res, next) {})

Thanks.

阿神
阿神

闭关修行中......

reply all(1)
世界只因有你

Isn’t it very convenient to use express for static routing? I recently migrated my local blog directly to the server. I still use express for my static routing

app.use(express.static(path.join(__dirname, 'public')));
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template