Local server with domain name setup on host file redirects to the digitalocean server

Posted March 2, 2017 7.3k views

Me and my team are trying to setup a local development central server for office use and ease access to development server, we are using a VMware *to host an *Ubuntu 16.04 server which will be used as a central testing server for the development team. The setup looks like the following:

Production server is hosted in *DigitalOcean *(of course) with 2 vhost configured in nginx

  • main site:
  • beta site: IP is setup by digitalocean

Development server is in a VM (VMWare) from the development HQ supporting for 3 network interfaces:

  1. eth0 - NAT network
  2. eth1 - Host-only Network
  3. eth3 - Bridge adapter

We are in the process of setting up local DNS server right now, but our current solution should have worked.

Our current solution is as follows:
We have manually configured all our computer’s Host File with the following entry is the IP address from eth3 which is configured as a static IP address setup by the network router.
If we try to ping the server via the provided domain we get the expected result.

$ ping

Pinging [] with 32 bytes of data:
Reply from bytes=32 time<1ms TTL=64
Reply from bytes=32 time<1ms TTL=64
Reply from bytes=32 time<1ms TTL=64
Reply from bytes=32 time<1ms TTL=64

upon installation of nginx we tried to do an HTTP request on the server using and got what we expected “The default page of Nginx” but when we started configuring the using the steps from How To Install WordPress with LEMP on Ubuntu 16.04 Guide to enable PHP support and tried to request again, it redirects us to which is the production server. We do not understand why this is happening. The vanila nginx function as expected but the PHP configured nginx redirect us to production server.

The nginx configuration is as follows

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /home/master/www;
        index index.php index.html index.htm;
        location / {
                try_files $uri $uri/ =404;
        location ~ \.php$ {                                                    
               fastcgi_split_path_info ^(.+\.php)(/.+)$;                                           
               fastcgi_pass unix:/var/run/php5-fpm.sock;                      
               fastcgi_index index.php;                                       
               include fastcgi_params;                                        
        location ~ /\.ht {       
                deny all;        
  • Have you also added to the host file of the development server?
    It shouldn’t be doing anything, just by added PHP to Nginx. That’s weird.
    But if you add WordPress, it has many places where it does redirects.

  • Hi, thank you for the response, we have a snapshot where Wordpress isn’t installed yet and it still redirects. I create a file called info.php, it contains the following:


    still redirect’s. It is weird because it shouldn’t do that.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


The only issue I can see with the server block you’ve provided is the default location block for /. By default, that’s going to result in 404’s.

location / {
    try_files $uri $uri/ =404;

The above is essentially saying that if the requested location doesn’t exist (file or directory), return a 404.

Since permalinks follow a directory-like structure, the paths in the URL will never actually resolve to a real directory or file, so the result would be a 404.

I would recommend changing that to:

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

I also recommend using a slightly modified location block for PHP-FPM by changing:

location ~ \.php$ { 


location ~ [^/]\.php(/|$) {

You’ll need to reload or restart NGINX for those changes to take effect once saved.

Beyond the above changes, are there any other server blocks active and can you post your NGINX configuration file?

cat /etc/nginx/nginx.conf

There’s nothing in that server block that should be causing a redirect, so we need to look elsewhere. I would also recommend checking the log files to see if there’s anything popping up there.

tail -20 /var/log/nginx/error.log