Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Last active April 7, 2024 15:17
Show Gist options
  • Save gilangvperdana/6b0b57aa3d7fac58d102136eebf848a0 to your computer and use it in GitHub Desktop.
Save gilangvperdana/6b0b57aa3d7fac58d102136eebf848a0 to your computer and use it in GitHub Desktop.
Nginx Parameter

Activate Log Rotate Nginx

nano /etc/logrotate.d/nginx
/var/log/nginx/*.log {
        daily
        missingok
        rotate 7
        size 5k
        compress
        delaycompress
        notifempty
        create 0640 www-data adm
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi \
        endscript
        postrotate
                invoke-rc.d nginx rotate >/dev/null 2>&1
        endscript
}
sudo logrotate -v -f /etc/logrotate.d/nginx

Activate log

nano /etc/nginx/nginx.conf
access_log /var/log/nginx/access.log custom;
error_log /var/log/nginx/error.log;

Forward Client IP / Source IP

nano /etc/nginx/conf.d/*.conf
proxy_set_header   X-Real-IP        $remote_addr; 
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; 

Set Real IP

nano /etc/nginx/nginx.conf
http {

set_real_ip_from 10.8.0.1/32;
real_ip_header X-Forwarded-For;

}

Log Format

nano /etc/nginx/nginx.conf
http {

log_format  custom  '$remote_addr - $remote_user [$time_local] "$request" "$request_body"'
		    ' "$http_UID" $status $body_bytes_sent "$http_referer" '
		    '"$http_user_agent" "$http_x_forwarded_for"';

}

Activate File Browser

server {
    listen 80;

    location / {
	root /your/file/directory/;
        autoindex on;
        allow all;
    }
}

GeoIP

Dynamic Server Name

NGINX AutoIndex

To be Updated~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment