nginx virtual host redirects to localhost

Angela asked:

I have an nginx configuration where the virtual host keeps getting redirected to the localhost. I have tested and reloaded the configuration, /etc/hosts is doing the current name resolution, and I have cleared the browser cache.

This is my nginx.conf

user www-data www-data;
worker_processes 4;
pid /var/run/;

events {
    worker_connections 1024;
    # multi_accept on;

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

And this is my idu-lms.main config

server {  
    root        /var/www/wordpress/htdocs;  
    index       index.html index.php;  
    server_name idu-lms.main www.idu-lms.main;  
    error_log   /var/log/nginx/idu-lms.main.error.log;  
    access_log  /var/log/nginx/idu-lms.main.access.log;  

    location / {
        try_files   $uri $uri/ /index.php?$args;

    location ~ \.php$ {
        include     fastcgi_params;
        fastcgi_pass    unix:/var/run/php5-fpm.sock;

and finally /etc/hosts   localhost   my-virtual-machine   idu-lms.main

My answer:

There are no redirects in your nginx configuration, so it is most likely that the application (WordPress) is sending the redirect.

If you accidentally set up WordPress with the URL of http://localhost/ then it will always attempt to redirect to localhost. In this case, you will need to change the URL that WordPress uses.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.