IP-based virtual host on Nginx

1

I'm trying to set up and serve WordPress on a DigitalOcean droplet that I purchased. As of now I don't have a domain name and would like to run it as http://139.59.21.155. Here's what my Nginx sites-enabled file looks like:

server {
    listen 80;
    listen [::]:80;

    root /home/ankush/wp_fu_main;
    index index.php index.html index.htm;

    location / {
            # try_files $uri $uri/ =404;
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
    }

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}

The WordPress setup is in the directory /home/ankush/wp_fu_main. So far, all I have managed to get is a blank page. There's nothing in the error logs as well (/var/log/nginx/error.log). What am I doing wrong? How do I know that Nginx is even picking up these requests?

ankush981

Posted 2016-12-04T18:36:49.653

Reputation: 165

You need to check the access log to see if it's reporting hits. Look at the config files in my Wordpress/AWS/Nginx tutorial, I think your listen and try_files are suspect. https://www.photographerstechsupport.com/tutorials/hosting-wordpress-on-aws-tutorial-pt1-introduction-configuration-downloads/#wpmu-nginx-configuration-files

– Tim – 2016-12-04T18:56:31.833

@Tim Yes, I see the request in access log, although I see a ton of other requests as well. Frankly, I'm alarmed: http://pastebin.com/L4K01a7N What could these be?

– ankush981 – 2016-12-04T19:00:48.770

@Tim I changed my listen directive also to what's the standard example in tutorials (see original post). Still I'm getting a blank screen. I don't know what to put in the server_name directive so I just removed it. – ankush981 – 2016-12-04T19:05:59.137

Could be automated bots looking for systems that can be taken over. Could be a process on your server. Which are your requests? The change to try_files is the key one I made. Your second listen command is for IP6. – Tim – 2016-12-04T19:09:53.213

I would suggest checking the php-fpm error log instead... – user1686 – 2016-12-04T19:12:22.837

@Tim Mine are from the IP 122.161.6.188. Rest I don't know, and they're scary! :D What do you mean by "The change to try_files is the key one I made"? Was it in reference to something else? – ankush981 – 2016-12-04T19:12:33.473

@grawity I could find the file /var/log/php7.0-fpm.log and it's blank. Where else can I look? From what I gather, Nginx will write all errors to its error log. No? – ankush981 – 2016-12-04T19:17:24.877

If you can't understand how to change try_files as per my examples I can't help you. – Tim – 2016-12-04T19:43:03.047

@Tim Ah, so it's the link you shared. I thought you had made changes somewhere and were asking me to look at it. :-) Okay, so I looked into the WordPress Single Site and changed my file to try_files $uri $uri/ /index.php?$args;. Still no luck, though. :( – ankush981 – 2016-12-04T19:49:59.847

You're going to need to do some diagnostics and/or share much more information. – Tim – 2016-12-04T20:04:16.183

@Tim Sure! What would you like me to share? – ankush981 – 2016-12-04T20:07:20.343

You're going to have to use a process of elimination to work out what's up, or hire someone. It looks like misconfiguration but there are so many places you can misconfigure and so much information that could be relevant. I'd start from scratch, check default Nginx page works, then work forward checking each step. – Tim – 2016-12-04T20:09:33.723

@Tim Thanks, but I was finally able to solve it. See my answer below. :-) – ankush981 – 2016-12-05T05:56:19.153

Answers

0

I was able to solve this by making a desperate Google search. Turns out that getting a blank page with Nginx on WordPress is a common problem and has something to do with FastCGI caching: https://www.narga.net/avoid-nginx-wordpress-blank-page/

ankush981

Posted 2016-12-04T18:36:49.653

Reputation: 165