使用nginx

时间:2018-05-31 16:55:55

标签: nginx

我想用nginx实现以下功能。有一个域具有不同的路径。每个路径都应该将请求代理到不同端口上的主机:

https://example.com/path1 -> 10.0.0.1:8081
https://example.com/path2 -> 10.0.0.1:8082
https://example.com/path3 -> 10.0.0.1:8083

这样的事情不起作用:

location /path1 {
  proxy_pass http://10.0.0.1:8081;
}

location /path2 {
  proxy_pass http://10.0.0.1:8082;
}

location /path3 {
  proxy_pass http://10.0.0.1:8083;
}

这种情况可能吗?

编辑:

这是nginx服务器上的配置

server {
  server_name example.com;

  listen [::]:443 ssl ipv6only=on;
  listen 443 ssl;
  ssl_certificate /some/path/fullchain.pem;
  ssl_certificate_key /some/path/privkey.pem;
  ssl_dhparam /some/path/ssl-dhparams.pem;

  location /path1 {
    proxy_pass http://10.0.0.1:8081;
  }

  location /path2 {
    proxy_pass http://10.0.0.1:8082;
  }

  location /path3 {
    proxy_pass http://10.0.0.1:8083;
  }
}

server {
  if ($host = example.com) {
    return 301 https://$host$request_uri;
  }

  listen 80 default_server;
  listen [::]:80 default_server;

  server_name example.com;
  return 404;
}

使用此配置,加载站点时将删除前缀路径。

https://example.com/path1/some/url -> https://example.com/some/url

0 个答案:

没有答案