Question

IP visitor comments is exactly like my IP droplet. So I can not cut off the spammers by their IP

I have site on wordpress, and IP visitor comments is exactly like my IP droplet. So I can not cut off the spammers by their IP. How to make that when someone write a comment on the website, admin panel recorded the actual visitor’s IP?


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.

@dvolob

Ok, here’s what we’re going to do. First, deploy a Droplet using Ubuntu 16.10 64bit, preferably a 1GB or 2GB instance. Since we’re running NGINX, PHP-FPM, and MariaDB plus the fact that you’re hosting multiple WordPress installations, we need more resources than would be available on an instance w/ only 512MB.

Once the Droplet is setup, login as root.

Installing NGINX, PHP 7.1.x + PHP-FPM, and MariaDB

Copy + Paste the command from here to the CLI.

You’ll see a dialog box pop up and ask “A new version of /boot/grub/menu.lst is available, but the version installed currently has been locally modified.” – simply hit enter (which selects “keep the local version currently installed”).

What the above command will do seems complex, due to size, but what it specifically does is:

1). Sync current packages against Ubuntu’s repositories. 2). Upgrade all existing packages to their latest versions. 3). Install the build environment needed for NGINX. 4). Install a new PPA so we can use PHP 7.1.x instead of 7.x. 5). Install the most used PHP packages, including PHP-FPM. 6). Download OpenSSL, PCRE, and ZLIB to compile NGINX. 7). Compile NGINX from source. 8). Remove files that we don’t need. 9). Install MariaDB

Once NGINX has finished compiling, it’ll begin installing MariaDB.

Securing MariaDB

Once MariaDB is finished up, we’ll run one more command to wrap up our software installation and to remove un-needed data from MySQL. Simply copy & paste the following command and hit enter.

mysql_secure_installation

In order, do the following:

1). Enter Current Root Password – Hit Enter (one hasn’t been set yet) 2). Set Root Password? – Type y, hit enter, and set a secure password. 3). Remove Anonymous Users? – Type y and hit enter. 4). Disallow root Login Remotely? – Type y and hit enter. 5). Remove test database and access to it? – Type y and hit enter. 6). Reload privilege tables now? – Type y and hit enter.

We’ve now successfully install NGINX from source, PHP 7.1.x + PHP-FPM, and MariaDB.

Configuring NGINX

Now, to get NGINX working the way we want, we need to modify a few files and create a few more directories. To get the directories created, we’ll run:

sudo mkdir -p /etc/nginx/sites \
&& sudo mkdir -p /etc/nginx/config/php

The above are simply storage directories for our websites and PHP configuration.

Now we’ll delete the current NGINX configuration file and create a new one with this configuration. Simply copy everything there and paste it in to the new nginx.conf file that we create with the below command.

sudo rm -rf /etc/nginx/config/nginx.conf \
&& sudo nano /etc/nginx/config/nginx.conf

Now let’s create our first website server block. We’ll store our website server blocks in the sites directory we created above, so:

sudo nano /etc/nginx/sites/example.com.conf

With that file open, we’ll paste in:

server {
    listen                                          80;
    server_name                                     yourdomain.com www.yourdomain.com;
    root                                            /home/yourdomain/htdocs/public;
    index                                           index.php index.html index.htm;

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

    include                                         /etc/nginx/config/php/php-fpm.conf;
}

Now we need to create our php-fpm.conf file which is required by the above server block. So like the above, we’ll create that file in our newly created php directory.

sudo nano /etc/nginx/config/php/php-fpm.conf

and paste in the contents from this gist.

NGINX is now configured and can be started by running:

nginx

When changes are made, you can reload those changes using:

nginx -s reload

Configuring PHP-FPM

The last thing we need to do is change the way PHP-FPM listens for connections. By default, it uses sockets. This is fine, TCP is most ideal for a multi-site environment.

So we need to open the existing file:

sudo nano /etc/php/7.1/fpm/pool.d/www.conf

and change:

listen = /run/php/php7.1-fpm.sock

to

listen = 127.0.0.1:9000

Then restart PHP-FPM:

sudo service php7.1-fpm restart

What Do I Do Now?

The server block we just created needs to be modified to match a real domain and you need to set a real root path so NGINX knows where to direct requests. Once this is done, you can create an index.php file in the root directory and test the configuration out.

From there, you can create a MySQL Database + User using the MySQL CLI or Adminer/phpMyAdmin (web-based interface) and test a WordPress installation.

How Do I Add New Sites?

You can drop new server blocks in /etc/nginx/sites/ and once set, reload NGINX to make the changes stick, i.e.

sudo nano /etc/nginx/sites/newsite.net.conf

Paste in your configuration…

nginx -s reload

Of course, create the directories for each site and make sure the root path is set for each domain.

You can in fact get a little more complex, but before we go in to creating PHP-FPM configurations for each account, I want to make sure we get this setup first!

@dvolob

Is there a specific reason you’re using both Apache + NGINX? I ask as unless you’re familiar with both and able to administer both, you’re really making things a multitude more complex than they need to be (i.e. you’re making your life harder).

Would you be open to allowing me to help you simplify things? By that, I mean dropping Apache and setting up with NGINX + PHP-FM + MariaDB (a drop-in replacement for MySQL).

If so, I can provide you with a very simple way of getting it all setup and you’ll only need to handle a few things afterwards.

If this block proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $ scheme;

is added to

location ~ \ .php $ { fastcgisplitpathinfo ^ (+ \ php…) $ (*.); root $ rootpath; include / etc / nginx / fastcgiparams; fastcgipass 127.0.0.1:9000; fastcgiparam REMOTEADDR $ httpxrealip; fastcgiindex index.php; }

all * .php starts to work! But IP is not transmitted at all, there is an empty space in site page where is to be output IP.