使用proxy_pass在位置中使用nginx正则表达式

时间:2014-03-31 00:35:39

标签: nginx reverse-proxy

我正在尝试设置一个简单的反向代理。我希望http://proxy.myserver.com/X/Y/something/somethingelse的请求代理http://videoX.sY.server.local/something/somethingelse

使用下面的配置我只收到来自nginx的404。

这可能吗?如果是的话,我做错了什么?

nginx.conf:

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    include /etc/nginx/conf.d/*.conf;
}

proxy1.conf:

server {
  listen 80;
  server_name proxy.myserver.com;

  more_set_headers 'Access-Control-Allow-Origin: *';
  more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE';
  more_set_headers 'Access-Control-Allow-Credentials: true';
  more_set_headers 'Access-Control-Allow-Headers: Origin,Content-Type,Accept';

  location /(\d+)/(\d+)/ {
    if ($request_method = OPTIONS ) {
      add_header Content-Length 0;
      add_header Content-Type text/plain;
      return 204;
    }

    proxy_pass                  http://video$1.s$2.server.local;
    proxy_redirect              off;
    proxy_connect_timeout       90;
    proxy_send_timeout          90;
    proxy_read_timeout          90;
    client_max_body_size        10m;
    proxy_buffer_size           4k;
    proxy_buffers               4 32k;
    proxy_busy_buffers_size     64k;
  }

}

由于

0 个答案:

没有答案