Belajar NGINX Bagian 002 Konfigurasi Awal

Belajar Nginx Bagian 002 merupakan salah satu rantaian tutorial / panduan untuk menggunakan Nginx sebagai Web Server.
2163  
       

Latarbelakang

Belajar Nginx Bagian 002 merupakan salah satu rantaian tutorial / panduan untuk menggunakan Nginx sebagai Web Server, Proxy Server maupun Reverse Web Server. Nginx sangat banyak digunakan karena dinilai sangat ringan jika dibandingkan dengan web server lainya. Dalam tutorial kali ini akan dibahas pengaturan supaya nginx dapat berjalan.

 

 

Konfigurasi Awal Nginx

/etc/nginx/nginx.conf


# For more information on configuration, see:
# * Official English Documentation: https://nginx.org/en/docs/
# * Official Russian Documentation: https://nginx.org/ru/docs/

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log ;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;

pid /var/run/nginx.pid;

events {
 worker_connections 472;
 multi_accept on;
 use epoll;
}

http {
	index index.html index.php;
	include /etc/nginx/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" $time_iso8601';
	#log_format main '$remote_addr - $remote_user [$time_local] '
	# '"$request" $status $body_bytes_sent ' server_tokens off;
	# '"$http_referer" "$http_user_agent"';

	sendfile on;
 tcp_nopush on;
 tcp_nodelay on;

	access_log /var/log/nginx/access.log;

	#keepalive_timeout 0;
 keepalive_timeout 65;

	types_hash_max_size 2048;

	#gzip config;

	gzip on;
	gzip_http_version 1.1;
	gzip_min_length 1100;
	gzip_buffers 4 32k;
	gzip_types text/plain application/x-javascript text/xml text/css;
	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 2;

 # Load config files from the /etc/nginx/conf.d directory
 # The default server is in conf.d/default.conf
 fastcgi_cache_path /usr/share/nginx/cache/fcgi levels=1:2 keys_zone=microcache:10m max_size=1024m inact$
 include /etc/nginx/conf.d/*.conf;

}

Jika file telah ada pastikan backup dulu.
/etc/nginx/fastcgi.conf

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

setingan awal untuk /etc/nginx/conf.d/default.conf
untuk yang virtual.conf nya dikosongkan saja


server {
	listen 80;
	server_name _ _.rompikulit.com; # isi dengan garis bawah ( _ ) untuk menerima semua domain atau ip.
	root /home/ec2-user/htdocs/rompikulit.com/;
	#access_log /dev/null; # untuk menghilangkan log
	#error_log /dev/null;  # untuk menghilangkan log

	location / {
		#autoindex on;
		try_files $uri $uri/ /index.php?$args;
	}

	location @xmlrewrite {
		# Some modules enforce no slash (/) at the end of the URL
		# Else this rewrite block wouldn't be needed (GlobalRedirect)
		rewrite ^/(.*)$ /index.php?q=$1;
	}
	## XML Sitemap support.
	location = /sitemap.xml {
		try_files $uri @xmlrewrite;
	}

	location /wp-includes/ { internal; }

		location ~* \.(js|css|jpg|jpeg|gif|png|ico)$ {
		log_not_found off;
		access_log off;
		add_header ETag "";
		if (-f $request_filename) {
			expires max;
			break;
		}
	}

	location ~ \.php$ {
		#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
		include fastcgi.conf;
		client_max_body_size 20m;
		client_body_buffer_size 128k;
		fastcgi_intercept_errors on;
		fastcgi_pass 127.0.0.1:9000;
		#fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		fastcgi_read_timeout 1000;
		fastcgi_param ENVIRONMENT production;
		fastcgi_buffer_size 128k;
		fastcgi_buffers 256 16k;
		fastcgi_busy_buffers_size 256k;
		fastcgi_temp_file_write_size 256k;
	}

}

Untuk mengecek user apa yang menjalankan nginx, bisa menggunakan kode ini.

ps -eo user,comm | grep nginx

2 Responses to “Belajar NGINX Bagian 002 Konfigurasi Awal”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>