Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Well, I'm really confused. I have a web server running nginx inside a virtual machine. I'm fowarding the port 8082 from the host machine to the port 80 in the virtual machine. In fact, going to exampledomain.dev:8082 works as expected showing the web page.

The problem happens when I type a url like this exampledomain.dev:8082/subdirectory

The browser redirect me to exampledomain.dev/subdirectory without the port number, so nothing works. But if I add a trailing backslash in the url like this exampledomain.dev:8082/subdirectory/ it works properly.

My question is, how can I point exampledomain.dev:8082/subdirectory and exampledomain.dev:8082/subdirectory/ to the same place and how I prevent nginx from removing the port number?

If is important, this is my actual nginx configuration inside the virtual machine:

server {
    listen 80;
    server_name exampledomain.dev;
    root /srv/www/exampledomain;
    index index.php;
    rewrite ^([^.]*[^/])$ $1/ permanent;

    location /subdirectory {
        try_files $uri $uri/ /subdirectory/index.php?$args;
share|improve this question

1 Answer 1

up vote 1 down vote accepted

The simplest fix is to change your rewrite to

rewrite ^([^.]*[^/])$ http://exampledomain.dev:8082/$1/ permanent;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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