Wednesday, December 4, 2019

Restricted Access to the website with http basic authentication for additional security layer

Restricted Access to the website with http basic authentication for additional security layer

##############
#For Nginx Server
##############
#Restricted Acccess to the website
#Creating login Username and Password
#SSH access to site folder or root and follow below command line

to create first user >> sudo htpasswd -c /etc/apache2/.htpasswd user1
to create more user >> sudo htpasswd /etc/apache2/.htpasswd user2

Then,

#Add the following code in Nginx server block

    auth_basic              "Restricted Area";
    auth_basic_user_file    /etc/apache2/.htpasswd;

#End - Restricted Access to view the website

check nginx block >> sudo nginx -t
restart nginx >> sudo systemctl nginx restart


###############
#For Apache Server
###############

#Creating login Username and Password
#SSH access to site folder and follow below command line

[sitefolder]:public_html$ sudo htpasswd -c .htpasswd name-of-user
New password:
Re-type new password:
Adding password for user name-of-user
[sitefolder]:public_html$

#End creating User and Password


Then,


#Add in the following code in .htaccess for Restricted Access
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /public_html/.htpasswd
require user dbadmin
#End Restricted Access

Friday, November 29, 2019

How to Redirect Subdomain to another Domain in Nginx

#Add server block as bellow to redirect yourolddomin.com to yournewdomain.com
#Redirect subdomain "mail.yourdomain.com" to subfolder "yourdomain.com/mail"

server {
    listen 80;
    server_name yourolddomain.com;
    return 301 $scheme://yournewdomain.com$request_uri;
}

#To redirect folder to subdomain
#If want to redirect permanently, change "redirect" to "permanent"

rewrite ^/images/(.*)$ http://images.example.com/$1 redirect;

Tuesday, February 19, 2019

Nginx Server Block

server {
listen 80;

# Allow IP
# allow 111.11.11.111; #IP address

# Block all
# deny all;

# added with Expires map
expires $expires;

# disable any unwanted HTTP methods
if ($request_method !~ ^(GET|HEAD|POST)$)
{
    return 444;
}

# enable compression
gzip on;
    gzip_comp_level    9;
    gzip_min_length    10240;
    gzip_proxied       expired no-cache no-store private auth;
    gzip_vary          on;

gzip_types
    application/atom+xml
    application/javascript
    application/json
    application/ld+json
    application/manifest+json
    application/rss+xml
    application/vnd.geo+json
    application/vnd.ms-fontobject
    application/x-font-ttf
    application/x-web-app-manifest+json
    application/xhtml+xml
    application/xml
    font/opentype
    image/bmp
    image/svg+xml
    image/x-icon
    text/cache-manifest
    text/css
    text/plain
    text/vcard
    text/vnd.rim.location.xloc
    text/vtt
    text/x-component
    text/x-cross-domain-policy;
    # text/html is always compressed by gzip module

location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
        expires 7d;
        #add_header Cache-control "public, no-transform";
        add_header ETag "";
    }
# enable compression

# added for stronger on Let's Encrypt SSL
ssl_dhparam /etc/ssl/certs/dhparam.pem;

# to increased upload file size
client_max_body_size 128m;

# for cookies
large_client_header_buffers 4 16k;

root /var/www/html/yourdomain.com;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name domian.com www.domain.com;

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;

# to increased upload file size
fastcgi_param PHP_VALUE "upload_max_filesize=128M \n post_max_size=128M";
}

# XSS Protection
add_header X-XSS-Protection "1; mode=block" always;

# to disable content-type sniffing on some browsers
add_header X-Content-Type-Options nosniff always;
 
# config to enable HSTS(HTTP Strict Transport Security)
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";

# for security
add_header X-Frame-Options SAMEORIGIN;

# access log off
access_log off;
log_not_found off;
error_log /var/log/nginx-error.log warn;

}

Monday, June 11, 2018

URL Redirections via htaccess

#301 Permanent redirect for sub-folder to main domain
RewriteEngine On
RedirectMatch permanent ^/subfolder/$ http://www.yourdomain.com/

#302 Temp redirect
RewriteEngin On
RedirectMatch 302 ^/subfolder/$ http://www.yourdomain.com/

#Redirect from http://www.yourdomain.com/subfolder/(post-url) to http://www.yourdomain.com/(post-url)
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com
RewriteRule ^subfolder/(.*)$ http://www.yourdoamin.com/$1 [L,R=301]

#Redirect from subdomain’s subdirectory (sub.yourdomain.com/subfolder/(post-url) to http://www.mysample.com/(post-url)
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub.yourdomain.com
RewriteRule ^subfolder/(.*)$ http://www.yourdomain.com/$1 [L,R=301]

#Direct root domain to sub-folder index file
DirectoryIndex welcome/index.html

#Redirect old domain to new domain with exact same URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]

#Redirect old sub-directory url to specific new url
RedirectMatch 301 ^/sub1(.*)$ https://yourdomain.com/new-url.html
#Multiple sub-directories
RedirectMatch 301 ^/sub1/sub2/sub3(.*)$ https://yourdomain.com/new-url.html

#Redirect old file path to new file path
Redirect /v1/en/store-locator.html https://www.newlink.com/en/store-locator.html

#This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/


Wednesday, June 7, 2017

Useful htaccess (HyperText Access) configuration to control Apachee Web server

.htaccess is a configuration file for use on web servers running the Apache Web Server software and below is some of useful configuration.
1. Create .htaccess file with notepad or any text editor and paste it below code
2. Upload it into your web server and remove ".txt" after uploaded

For more info: http://www.htaccess-guide.com/

+============================+
 # Note: Hash sign (#) for comments

#Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

#Redirect non-www to www (Option 2)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Change .php extension to .html
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [nc]

#Force https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#Force https (option 2)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

#Force https (option 3)
#Force www / https
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [L,R=301,NC]

# Directory Index: You can change a default index file from another directory (eg. index.php is inside welcome folder)
# DirectoryIndex welcome index.php

# Access Control: You can Deny / Allow over specific IP address and it's useful when you are doing site updates
Order deny,allow
# Deny all public access
Deny from all
# Allow your IP address so only you can see the site
Allow from xxx.xx.xx.xxx
# Redirect your users to a temporary an error page, welcome page or maintenance page during site update/development with your custom page
ErrorDocument 403 /welcome/comingsoon.php

# Prevent Directory Browsing (Disable/Enable)
# To Disable
Options All -Indexes
# To Enable
# Options All +Indexes

# Create custom error pages and do not forget to create related error html file in source
# And you can extend this like as well:
# ErrorDocument 400 /400.html #400 - Bad Request
# ErrorDocument 401 /401.html #401 - Not Authorized
# ErrorDocument 403 /403.html #403 - Forbidden
# ErrorDocument 404 /404.html #404 - Not Found
# ErrorDocument 500 /500.html #500 - Internal Server Error
# ErrorDocument 502 /502.html #502 - Bad Gateway
# ErrorDocument 504 /504.html #504 - Timeout Error
+============================+

Friday, February 17, 2017

Use Google DNS for faster website load on your compuer

In order to configure on your computer, please follow below step:

- Open Network and Sharing Center by right clicking on network icon of your right hand side of Task Bar
- Click on "Local Area Connection" (will appeared connection status dialog box)
- Click on "Properties"
- Select "Internet Protocol Version 4 (TCP/IPv4)
- Click on "Properties" (will appeared Internet Protocol Version 4 dialog box)
- Choose "Use the following DNS server address and key in the following google DNS server numbers
~ Preferred DNS Server: 8.8.8.8
~ Alternate DNS Server: 8.8.4.4

Then click "OK" to save the setting and now you are using Google DNS server with faster DNS lookups and improve security and read more here -> https://developers.google.com/speed/public-dns/

Wednesday, February 15, 2017

Page Jumps with Anchor Links #

If you want to create page jumps with anchor link code, you will need these two elements:
- The link
- The target

Example:
- Create the Link:
<a name="youlinktext">yourlinktext</a>

and link to the Target:
<a href="#yourlinktext">go to your link text</a>

- Link to div tag with id:
<div id="#yourlinkname">

- Linking to the Top of the Page:
Add the “target code” at the very top of your page:
<a name="toppage"></a>

And then put the following link code at the bottom of the page with "#"
<a href="#toppage">Top</a>

- Link to different page
<a href="../yourURL/#yourlinkname">Go To Next Page</a>

To get Smooth Page Scroll Effect, you may put the following jquery code right before body tag:

<!-- Start SMOOTH PAGE SCROLL -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});
</script>
<!-- End SMOOTH PAGE SCROLL -->

Credit: Jquery code snippets by Chris Coyier and here is example on codepen:  http://codepen.io/chriscoyier/pen/dpBMVP


Restricted Access to the website with http basic authentication for additional security layer

Restricted Access to the website with http basic authentication for additional security layer ############## #For Nginx Server #########...