Why does my server always redirect to localhost when I visit a subdirectory on the server?
System admins and Linux gurus, here’s one for you:
I’m a bit of a newbie at this. I installed nginx on a server that originally ran apache2. I tested out nginx and found that going to the server’s address worked fine, but whenever I went to http://serverip/folder it would redirect to http://localhost/folder and because I had nothing running on localhost, it would give me a 404 error.
I decided that I would try nginx at a later date and uninstalled it using apt-get—purge remove nginx and switched back to apache2.
When I started up apache2 I discovered that it had the same problem as well.
Yes, I have checked the hosts file on my machine, and on the server.
Yes, I made sure there was only one server daemon running at a time.
Yes, I have Googled it.
Can anybody help? I’m more than happy to provide my config files if you need them.
Observing members:
0
Composing members:
0
8 Answers
So, the server is different than the machine you’re working on? If that’s the case, I’d say make sure the server_name (or equivelent) is not set to “localhost”.
So, for nginex:
server {
listen 80 default;
server_name localhost;
server_name_in_redirect off;
that server_name should be set to the IP address of computer the server is running on.
I believe the servername directive in Apache’s httpd.conf does the same thing.
I could be really incredibly wrong, but that’s my best guess.
That appears to work!
Strangely enough, I tried that before, but it didn’t work.
Oh well. You take the car to a garage, and the check engine light turns off.
Computers are never working right unless they’re making their users look like nuts.
Actually, now it’s creating random 403 forbidden errors. I’ll take a look into this but if you happen to know off the top of your head what’s causing this could you please tell me?
And yes, I have checked the file permissions.
Thanks so much for your time!
If you’re trying to get to a directory rather than a file then you may have the directory browsing option turned off.
Or the option may be turned on, but there’s no file in there yet (or at least nothing like a ‘welcome.html’ or ‘index.html’ or whatever the default web page name is).
I’m not sure if a file permission problem will trigger a 403, but it’d be worth a look if the other two fail.
First one worked! Thanks a ton! I really appreciate your time.
Nice username, by the way. :-D
You are quite welcome. I know how incredibly frustrating these things can be.
Thanks :) I’ve had it since the days of BBS’.
Response moderated (Writing Standards)
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.