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

March 2, 2017 4.6k views
Nginx Ubuntu PHP Networking LEMP

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: www.website.com
  • beta site: beta.website.com 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 develop.website.com 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 develop.website.com we get the expected result.

$ ping develop.website.com

Pinging develop.website.com [] 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 develop.website.com 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 beta.website.com 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;
        server_name develop.website.com;
        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 develop.website.com 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.

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
Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!