How to Run CGI Script with Nginx

To run CGI scripts with Nginx, you can use the fcgiwrap package. 1. Install Nginx and fcgiwrap 2. Enable and start fcgiwrap 3. Configure Nginx Edit the server entry of the website for which you need CGI enabled and add the following configuration. Replace /var/www/html with the actual document root of your website. Example Configuration: 4. Restart Nginx 5. … Read more

How to send plain text response from Nginx

You can use a return statement in Nginx to send a plain text response. In your Nginx server entry, add location ~* “^/hello/(.*)” { default_type text/plain; return 200 “Hello $1\n”; } Now you can access the page with the URL boby@sok-01:~$ curl http://localhost/hello/World Hello World boby@sok-01:~$ Here is another example location “/hello” { default_type text/plain; … Read more

How to configure Security Headers in Nginx

You can add the following headers in your nginx.conf or server entry to improve website security add_header X-Frame-Options sameorigin; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection ‘1; mode=block’; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; add_header Content-Security-Policy “default-src https: data: ‘unsafe-inline’ ‘unsafe-eval'”; add_header Referrer-Policy strict-origin; See Nginx

Nginx configuration for Angular

Angular is a single-page application (SPA) framework. To serve Angular application using Nginx web server, use following configuration. server { listen *:80; root /var/www/html; index index.html; location / { try_files $uri$args $uri$args/ /index.html; } } You can build static files using the command ng build Upload the static files it builds, usually in the dist … Read more

Nginx Configuration for Drupal 7

Here is Drupal 7 server configuration for Nginx with letsencrypt SSL. server { listen 443 ssl http2; ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # managed by Certbot server_name yourdomain.com www.yourdomain.com; root /home/yourdomain.com/html/; index index.php index.html index.htm; access_log /var/log/nginx/yourdomain.com.log; error_log /var/log/nginx/yourdomain.com-error.log; client_max_body_size 1000M; proxy_read_timeout 600s; fastcgi_read_timeout 600s; fastcgi_send_timeout 600s; # Forbidden files or directories … Read more

How to install Engintron on Cpanel Server

Engintron is a Cpanel plugin that allows you to use the Nginx web server as a reverse proxy in front of the Apache webserver used by Cpanel. To install Engintron on Cpanel Server, run cd / rm -f engintron.sh wget –no-check-certificate https://raw.githubusercontent.com/engintron/engintron/master/engintron.sh bash engintron.sh install Nginx provides micro caching, speeding up websites hosted on the … Read more

Nginx Redirect HTTP to HTTPS

To force SSL (HTTPS) on a website hosted on an Nginx web server, edit server entry for the website, add Method 2 Method 3 Create a server entry for port 80, that only do the redirect to HTTPS like the following Restart Nginx Nginx > Nginx Redirect

Nginx php-fpm No input file specified

Nginx Web Server

When accessing PHP files from location block that have different document root specified using alias, i get error No input file specified. Here is the Nginx config i used server { listen 80; server_name lab.test; root /www/lab.test/html; autoindex on; index index.php; location /ok/ { alias /www/serverok.test/html/; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_intercept_errors on; fastcgi_buffers … Read more

How to hide Nginx version

Nginx Web Server

On a default installation of the Nginx web server, the error pages show the version of Nginx software running on your server. Displaying software version is not good for security and visitors don’t need to know what version of Nginx web server you are using. For hackers, if they know the version, they can see … Read more

Nginx Rate Limiting

Nginx Web Server

Nginx web server support rate-limiting with module ngx_http_limit_req_module. Block WordPress wp-login.php attack To block the WordPress wp-login.php attack, add the following to http section of your nginx.conf file. limit_req_zone $binary_remote_addr zone=WPRATELIMIT:10m rate=2r/s; limit_req_status 429; 2r/2 = Lmit 2 requests per second. Inside server entry for the website, add location ~ \wp-login.php$ { limit_req zone=WPRATELIMIT; include … Read more

How to redirect a domain with html extension in Nginx

A WordPress website needs to migrate to a different domain, on a new domain site use static HTML pages. On the source site, WordPress is configured to use URL like https://domain1/page-name/, on the new server, the same page available on URL https://domain2/page-name.html Source = https://domain1/page-name/ Destinatation = https://domain2/page-name.html To do the redirection, edit Nginx configuration … Read more