如何在nginx中为特殊路径设置反向代理?

时间:2017-12-12 03:29:30

标签: nginx reverse-proxy

如何在nginx中为特殊路径设置反向代理?

在我的Nignx的default.conf中:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        # root   /usr/share/nginx/html;
        root /var/www/html/website;
        index  index.html index.htm;

        try_files $uri $uri/ /index.html;

        proxy_pass http://107.120.30.76:8001;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

我只知道如何配置/根目录,如何配置特殊路径?

例如我请求http://107.120.30.76/api/*我要转移到http://107.120.30.76:8000/api/*。如何配置?

1 个答案:

答案 0 :(得分:1)

您可以将波纹管配置添加到服务器配置中:

res.render('tasklist', { user_id: req.params._id, tasks : docs });