Saturday , 21 December 2024
Home » Linux » Server » Install, Konfig, dan Manipulasi Header Nginx Debian – IPv6 Ready

Install, Konfig, dan Manipulasi Header Nginx Debian – IPv6 Ready

1. Download nginx dari web resminya
2. Install build-essential
3. Install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
4. Extract nginx
5. Edit pada folder src/html filenya tepatnya saya lupa yang penting ada kata header nya. Yang diubah adalah string headernya.
6. Compile dengan konfigurasi contoh berikut ini:

./configure 
    --prefix=/var/www 
    --sbin-path=/usr/sbin/nginx 
    --conf-path=/etc/nginx/nginx.conf 
    --pid-path=/var/run/nginx.pid 
    --lock-path=/var/lock/nginx.lock 
    --error-log-path=/var/log/nginx/error.log 
    --http-log-path=/var/log/nginx/access.log 
    --user=www-data 
    --group=www-data 
    --without-mail_pop3_module 
    --without-mail_imap_module 
    --without-mail_smtp_module 
    --without-http_uwsgi_module 
    --without-http_scgi_module 
    --with-ipv6 
    --with-http_stub_status_module 
    --with-http_gzip_static_module

#make
#make install

7. Buat init.d [/etc/init.d/nginx]

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
    . /etc/default/nginx
fi

set -e

. /lib/lsb/init-functions

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid 
        --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;
  stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid 
        --exec $DAEMON || true
    echo "$NAME."
    ;;
  restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --quiet --pidfile 
        /var/run/$NAME.pid --exec $DAEMON || true
    sleep 1
    start-stop-daemon --start --quiet --pidfile 
        /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;
  reload)
      echo -n "Reloading $DESC configuration: "
      start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid 
          --exec $DAEMON || true
      echo "$NAME."
      ;;
  status)
      status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
      ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
    exit 1
    ;;
esac

exit 0

# chmod +x /etc/init.d/nginx
# update-rc.d -f nginx defaults

8. Configurasi nginx di /etc/nginx/nginx.conf

user  www-data;
worker_processes  2; #sesuaikan dengan core cpu anda
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;


events {
    worker_connections  2048; #jumlah target client = worker_connections*worker_processes
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  15;
        gzip  on;
        gzip_disable msie6;
        gzip_types text/plain text/css application/javascript;
        gzip_vary on;
         gzip_comp_level 2;
        #client_max_body_size 3M;
    include /etc/nginx/sites-enabled/*;
}

9. Membuat modul sesuai keperluan vhost
/etc/nginx/sites-module/common.conf

# Global configuration file.
# ESSENTIAL : Configure Nginx Listening Port
listen 80;
listen [::]:80; # jika ingin mengaktifkan ipv6
# ESSENTIAL : Default file to serve. If the first file isn't found,
index index.php index.html index.htm;
# ESSENTIAL : no favicon logs
location = /favicon.ico {
    log_not_found off;
    access_log off;
}
# ESSENTIAL : robots.txt
location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}
# ESSENTIAL : Configure 404 Pages
error_page 404 /404.html;
# ESSENTIAL : Configure 50x Pages
error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www/html;
    }
# SECURITY : Deny all attempts to access hidden files .abcde
location ~ /. {
    deny all;
}
# PERFORMANCE : Set expires headers for static files and turn off logging.
location ~* ^.+.(js|css|swf|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    access_log off; log_not_found off; expires 30d;
}

/etc/nginx/sites-module/wordpress.conf

# WORDPRESS : Rewrite rules, sends everything through index.php and keeps the appended query string intact
location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*.php$ {
    deny all;
}
# REQUIREMENTS : Enable PHP Support
location ~ .php$ {
    # SECURITY : Zero day Exploit Protection
    try_files $uri =404;
    # ENABLE : Enable PHP, listen fpm sock
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include /etc/nginx/fastcgi_params;
}
# PLUGINS : Enable Rewrite Rules for Yoast SEO SiteMap
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

10. Membuat virtualhost, buat file pada direktori /etc/nginx/sites-available kemudian buat ln -s ke sites-enabled

server {
         listen 80 default_server;
 listen [::]:80 default_server;
      rewrite ^/(.*)$ https://www.muhammadhernawan.com/$1 permanent;
}

server {
    server_name muhammadhernawan.com www.muhammadhernawan.com;
   root /home/muhammadhernawan/public_html/www;
   error_log /var/log/nginx/www.muhammadhernawan.com.error.log;
        access_log off;
   include /etc/nginx/sites-module/common.conf;
   include /etc/nginx/sites-module/wordpress.conf;
}

server {
        server_name mail.muhammadhernawan.com;
        root /var/www/mail;
        error_log /var/log/nginx/mail.muhammadhernawan.com.error.log;
        include /etc/nginx/sites-module/common.conf;
        include /etc/nginx/sites-module/wordpress.conf;
}

11. Setting fastcgi_params tambahkan

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

selenjutnya saya akan share php server (php5-fpm) dan mariadb (sql).

Komentar Anda