0

I can't find any info on this so I don't know if it's even possible, but I was wondering: Can I use NGINX's rewrite module to change the displayed URL from, for example 123.123.123.123:6000/some/path, to something like my.domain.com/some/path?

The way it is now, I have a subdomain registered for this server, where domainFactory just has a redirect to this server.

Maybe I should approach this differently?

1
  • I fixed this by correctly setting up my DNS. In retrospect, what I was trying to do was kinda stupid. Noobs at work, sorry for wasting you guys' time.
    – Nico Weiss
    Feb 16, 2016 at 14:52

1 Answer 1

0

I see two potential ways to interpret your question:

1) You could mean a redirect instead of a "rewrite" (a web server term). You want to show the domain, not the IP to the client. That's a redirect.

server {
    listen 123.123.123.123:6000;

    return 301 https://my.domain.com$request_uri;
}

2) You could mean that traffic from there goes to a specific backend server. Again, I don't think you mean rewriting.

server {
    listen 123.123.123.123:6000;

    location / {
        proxy_pass http://my.domain.com;
        proxy_http_version 1.1;
        proxy_set_header Connection "Keep-Alive";
        proxy_set_header Proxy-Connection "Keep-Alive";
    }
}

To be more complete, perhaps you already have content for / and you only want some/path to be served by the other server:

server {
    listen 123.123.123.123:6000;

    location ~ /some/path {
        proxy_pass http://my.domain.com;
        proxy_http_version 1.1;
        proxy_set_header Connection "Keep-Alive";
        proxy_set_header Proxy-Connection "Keep-Alive";
    }

    location / {
        proxy_pass http://123.123.123.123:80;
        proxy_http_version 1.1;
        proxy_set_header Connection "Keep-Alive";
        proxy_set_header Proxy-Connection "Keep-Alive";
    }
}

This last one is a common technique to expose multiple micro-service systems as one, thus unifying the domain and simplifying SSL. In my case, I often map anything with _ to my Elasticsearch cluster.

2
  • I have already fixed my issue by fixing my DNS entry, what I was trying to do is basically just let the browser show another string instead of the IP.
    – Nico Weiss
    Feb 16, 2016 at 14:44
  • That would be the server_name line in Nginx (match by name not IP). You can use Nginx to cover a lot of problems with underlying systems. It's pretty cool.
    – David Betz
    Feb 16, 2016 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .