Question

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

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

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

192.168.1.100 develop.website.com

192.168.1.100 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 [192.168.1.100] with 32 bytes of data:
Reply from 192.168.1.100: bytes=32 time<1ms TTL=64
Reply from 192.168.1.100: bytes=32 time<1ms TTL=64
Reply from 192.168.1.100: bytes=32 time<1ms TTL=64
Reply from 192.168.1.100: 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;        
        }                        
}                                                              
Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@MarkHeramis

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$ { 

to

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