Redirect www and non-www http to non-www https on NGINX

16 sec read

How to set up redirect www and non-www http to non-www https

o nginx config file

vim /etc/nginx/sites-enabled/blackonsole.conf

# http
server {
  listen      80;
  server_name blackonsole.org www.blackonsole.org;
  return      301 https://blackonsole.org$request_uri;
}

# https
server {
  listen 443 ssl;
  server_name blackonsole.org;

  # redirect to non-www
  if ($host = 'www.blackonsole.org') {
    rewrite ^/(.*)$ https://blackonsole.org/$1 permanent;
  }
 
  # others
}

o testing config file and restart nginx

nginx -t
nginx -s reload

Hide PHP-FPM Version on NGINX

Check PHP-FPM version on NGINX HTTP response $ curl -I localhost/index.php HTTP/1.1 200 OK Date: Sat, 12 Aug 2017 14:07:54 GMT Content-Type: text/html Connection:...
sysadmin.id
16 sec read

Hide Server Info Response on NGINX

How to hide `Server:` Response info on NGINX $ curl -I localhost HTTP/1.1 200 OK Server: nginx/1.4.6 (Ubuntu) Date: Fri, 11 Aug 2017 14:09:04...
sysadmin.id
26 sec read

Block or ban ip with NGINX

How to block ip with NGINX 0. define block ip on nginx.conf vim /etc/nginx/nginx.conf http { geo $ban_ip { default 0; include ban_ip.conf; }...
sysadmin.id
23 sec read