0

I have an nginx reverse proxy that is using stream proxy to direct to a web page that uses NTLM authentication, but I need to use something similar to the location directive to tell this reverse proxy to send requests to that site to a specific IRL. For example, if a user were to request this site:

https://mysite.mydomain.com

I would like this to forward on to http://mysite.mydomain.com/xyz

Normally I would use location directive, but any time I add the location directive into my current config, I get the error "location" directive is not allowed here in /opt/nginx/nginx.conf:43

My current config (which is contains lots of stuff I've never done before due to the NTLM issues I've had), is shown below

/opt/nginx/nginx.conf

worker_processes 1;

events {
    worker_connections 1024;
}

stream {
    upstream backend {
       hash $remote_addr consistent;

       server mysite.mydomain.com:80 weight=5;
       server 192.168.0.50:80            max_fails=3 fail_timeout=30s;


    }

server {
    listen 443 ssl;

    ssl_certificate /usr/local/nginx/conf/mydomain.com.crt;
    ssl_certificate_key /usr/local/nginx/conf/mydomain.com.key;
    ssl_session_cache shared:SSL:10m;

    ssl_session_timeout 5m;

    proxy_connect_timeout 1s;
    proxy_timeout 3s;
    proxy_pass backend;

    }

}

I'm not sure how to add the /xyz URI. If I add it to the end of any ip's in this file, that's wrong, and if I try adding a location directive inside of the server section, I get that error.

Of course, Ideally, this would actually forward to any extension they put at the end of the url, and try that, for example /abc, or /xyz, would forward to http://mysite.mydomain.com/abc, and http://mysite.mydomain.com/xyz respectively. Any help is appreciated.

  • That's a fairly bare config, and I'm not very familiar with nginx streaming. Is the entire site just streaming, or does it serve some pages as well? I note that you don't have any locations defined, your server doesn't define server_name, and it's just fairly bare. I'd define a stream on a specific port, a server with a location to serve pages, and another location or server to do the redirection. I'd need more information to give you any more concrete recommendations - proper URLs (example.com is fine), ports, more context about the server, etc. – Tim Feb 17 '16 at 22:39
  • The site also has pages it needs to be served. I'm absolutely new to using reverse proxies, but I assumed that once the user were to get through the reverse proxy using the stream, that would be the end of the need for reverse proxy. Just to be clear, the entire site is behind that login which requires the stream. As I said in the question, I don't have any locations defined, because when I add a location I get an error (listed in the question). – trueCamelType Feb 17 '16 at 22:43
  • Please edit the question to indicate what services will run on which ports. eg server web pages on www.example.com port 80, serve an audio stream on port 12345 which is proxied from IP 1.2.3.4:56, redirect example.com to www.example.com, redirect example.com/abc to www.example.com. It's all pretty straightforward, but you should really read the documentation and some tutorials before you post a question about the basics. – Tim Feb 17 '16 at 22:47
  • The only thing I need is to specify a location for an NTLM service where the nginx server uses an nginx stream module. That's what the question asks, and that's all I need. I have read the documentation, and I didn't see anywhere that uses the nginx stream proxy and also a location section. I have also read tutorials. Also, I would hardly call this "basic". This seems pretty odd to me, and there are almost no questions related to this on SE. If you are able to find a question like this, or find docs that mention this, please link it to me. I'd be very grateful. – trueCamelType Feb 17 '16 at 22:59
  • I'm slightly confused, and I've never used the stream directive. I would put the proxy_pass within a location block rather than inside a server block, then create another location block for a simple redirect. Without further context and information I can't help further sorry. – Tim Feb 17 '16 at 23:35
0

The reason that I could not find how to set location within stream proxy in the stream docs is because it's not possible.

The location directive is only allowed in server{} sections inside the http{} section.

This would probably have been fairly intuitive if I knew more about the difference between how stream connections worked.

This answer was given by Maxim Dounin, who has been tons of help, and is awesome.

For anyone looking up exactly how to do this, the stream section is completely separate from the http section, and you can put everything you need in the http section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.