Problem Description
I'm running nginx in a Virtual Machine using NAT and I'm having redirection issues when I access it from the host machine.
### Works as expected
- `http://localhost:8080/test/index.htm`: works.
- `http://localhost:8080/test/`: works.
### Doesn't work as expected
- `http://localhost:8080/test`: redirects to `http://localhost/test/` . This is ***not*** what I want. **(notice it strips the port number)**
### What I've tried
Based on what I've googled, I tried `server_name_in_redirect off;` and `rewrite ^([^.]*[^/])$ $1/ permanent;`, both with no success.
### My default.conf:
server {
listen 80;
server_name localhost;
# server_name_in_redirect off;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ \.php$ {
# rewrite ^([^.]*[^/])$ $1/ permanent;
root /usr/share/nginx/html;
try_files $uri =404;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?