How to restart Nginx on macOS

We open a Terminal and use the one-liner command sudo nginx -s stop && sudo nginx to restart the Nginx on macOS. Restart the Nginx service. Terminal sudo nginx -s stop && sudo nginx Reload the Nginx configuration file. Terminal sudo nginx -s reload Table of Contents 1. Restart the Nginx on macOS 2. Reload …

Read more

How to check Nginx version

We can type the command nginx -v (lowercase v) in Linux, macOS, and Windows to show the Nginx version currently installed on our system. 1. Check Nginx version The Nginx with a lowercase v option, the nginx -V show the version and then exits. In the below output, Nginx version 1.21.0 is currently installed. Terminal …

Read more

Nginx + ModSecurity and OWASP CRS

This tutorial shows how to install ModSecurity (open source web application Firewall) in Nginx, and also enable the OWASP ModSecurity Core Rule Set (CRS). Tested: Nginx Open Source 1.17.7 ModSecurity 3.0 OWASP ModSecurity CRS 3.2.2 Debian The official guide of installing ModSecurity for NGINX is very detail and well documented, and you should refer it. …

Read more

Nginx + WordPress, 404 errors for all pages?

We installed Nginx, MariaDB, PHP, and WordPress on Mac OS. The homepage is displayed fine, but all other pages are returning 404 errors? Tested with Nginx 1.17.9 WordPress 5.4 PHP 7.4 Review the current Nginx + WordPress integration. nginx.conf server { listen 8080; server_name localhost; root /usr/local/var/www/wordpress; location / { index index.html index.htm index.php; } …

Read more

Nginx – Unit nginx.service is masked

Upgraded a Nginx Server to the latest 1.15.x, but hits the following error message : Terminal $ sudo service nginx status * nginx.service Loaded: masked (/dev/null; bad) Active: inactive (dead) $ sudo service nginx restart Failed to restart nginx.service: Unit nginx.service is masked. Solution To solve it, just unmask with this : sudo systemctl unmask …

Read more

Nginx + WordPress ERR_TOO_MANY_REDIRECTS

Fresh installs a WordPress on Windows for development, and hits the ERR_TOO_MANY_REDIRECTS error message? Tested URL : http://localhost/index.php/wp-admin/install.php Tested : PHP 7.1.10 WordPress 4.8.3 Nginx 1.12.1 MySQL 5.7.17 Windows 10 your-nginx\conf\nginx.conf upstream php { server 127.0.0.1:9999; } server { listen 80; server_name localhost; root www/wordpress; location / { try_files $uri $uri/ /index.php?$args; } location ~ …

Read more

Nginx + PHP on Windows

This article shows you how to install and integrate Nginx and PHP on Windows. Tested Nginx 1.12.1 PHP 7.1.10 Windows 10 1. Install Nginx + PHP Basically, just download zip file and extracts it, no installation. To install Nginx Visit http://nginx.org/en/download.html Download nginx/Windows-1.12.2 Extract to C:\nginx-1.12.1 To Install PHP Visit http://windows.php.net/download/ Download PHP7.1 download VC14 …

Read more

php-cgi.exe – The application was unable to start correctly

Run php-cgi.exe and hits a pop up dialog showing the following error message : Application Error : The application was unable to start correctly (0xc000007b) Terminal c:\php7.1>php-cgi.exe -b 127.0.0.1:9123 Tested with PHP 7.1.10 on Windows 10 Solution To run PHP on Windows, you need to install Redistributable for Visual Studio, refer to the official PHP …

Read more

Nginx + PHP – No input file specified

A common Nginx + PHP error message “No input file specified.” nginx.conf http { include mime.types; default_type application/octet-stream; server { listen 80; server_name localhost; location / { root www; index index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9999; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } Tested with Nginx 1.12.1 + PHP …

Read more

Nginx : Block Referrer Spam

In this article, we will show you how to block referrer spam in one of our Nginx web server. 1. Find the Patterns Check the Nginx access.log file, and identify the “referrer spam” patterns. $ sudo tail -f /var/log/nginx/access.log Some patterns : 200 http://???.ru/engine/redirect.php?url=http://mywebsite.com/site/blogspot.com.au 200 http://???.com/tp/out.php?link=alternatevideo&url=http%3A//mywebsite.com/site/readyliftproshop.com 200 http://???.edu/online/redirect.asp?url=http://mywebsite/site/wheretoshophongkong.com We are going to block following patterns …

Read more

Nginx + Apache Tomcat configuration example

This tutorial shows you how to configure Nginx as a reverse proxy to redirect the traffics from port 80 to Apache Tomcat on port 8080. Here is the environment in my Linode server : Debian 7.5 Nginx 1.2.1 Tomcat 7.0.28 P.S Both Nginx and Tomcat are installed via apt-get install. 1. Tomcat Configuration Edit server.xml, …

Read more

Nginx : Block User Agent

In Nginx, you can block certain user agents (normally it is crawler) like this : /etc/nginx/sites-enabled/default server { listen 80; server_name mysite.com; root /etc/tomcat7/webapps/mysite; if ($http_user_agent ~* (ahrefs|wget|crawler|majestic) ) { return 403; } location / { <!– xxx –> } } In above example, for “user agent” that contains one of this pattern : ahrefs|wget|crawler|majestic, …

Read more

Count IP address in Nginx access logs

Recently, many referer spam hit on my server, below is the command I used to find and count the IP Address from a Nginx access log file. $ sudo awk ‘{print $1}’ /var/log/nginx/access.log | sort | uniq -c | sort -nr Full example. $ sudo awk ‘{print $1}’ /var/log/nginx/access.log | sort | uniq -c | …

Read more