-4

First time using nginx. I want to forward any incoming request which looks like this: https://www.example.com/elasticsearch to http://localhost:9200 with nginx. I wrote following in my nginx config in the http tag.

server {
        listen 3333;
        server_name www.example.com/elasticsearch;
        return 301 $scheme://localhost:9200;
        location / {
                allow 'elasticsearch';
                deny all;
        }
}

Unfortunately when I use nginx -t I receive following emerg:

nginx: [emerg] invalid parameter "elasticsearch" in /etc/nginx/nginx.conf:79

1 Answer 1

1

server_name parameter contains only the server name, not any URI on the server.

You can do the rewrite like this:

server {
    listen 3333;
    server_name www.example.com;
    location /elasticsearch {
        return 301 $scheme://localhost:9200;
    }
}

If you want to deny access to other locations, which your config says but your question doesn't, you can use this location block in addition to the above:

location / {
    deny all;
}

You must log in to answer this question.

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