This page looks best with JavaScript enabled

Server Block Nginx

 ·   ·  ☕ 1 min read

Nginx Logo | https://dwglogo.com

Berikut contoh konfigurasi server block Nginx:

1
2
3
4
5
6
7
8
9
server {
  listen 80;
  listen [::]:80;

  server_name say.iqbal.es;
  root /var/www/say.iqbal;

  index index.html index.php;
}

Server block jika menggunakan php-fpm:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
server {
 listen 89;
 listen [::]:89;

 server_name _;
 root /var/www/whois;

 index index.php;

 location ~* \.php$ {
 fastcgi_pass unix:/run/php/php-fpm.sock;
 include	fastcgi_params;
 fastcgi_param	SCRIPT_FILENAME	$document_root$fastcgi_script_name;
 fastcgi_param	SCRIPT_NAME	$fastcgi_script_name;
  }
}

Jika menggunakan SSL, berikut contoh konfigurasinya:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
server {
  listen 80;
  listen [::]:80;

  server_name say.iqbal.es;
  return 301 https://$server_name$request_uri;
}
server {
        listen 443;
        server_name say.iqbal.es;
        root /var/www/say.iqbal;

        index index.html index.php;

        ssl on;
        ssl_certificate     /etc/letsencrypt/live/say.iqbal.es/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/say.iqbal.es/privkey.pem;
        ssl_session_timeout 15m;
        ssl_protocols SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
        ssl_prefer_server_ciphers on;
}

Generate SSL Let’s Encrypt di CentOS 7

Dan ini untuk konfigurasi Nginx sebagai Reverse Proxy:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
server {
  listen 80;
  listen [::]:80;

  server_name k.iqbal.es;

  location / {
      proxy_pass http://k.iqbal.es:6969;
  }
}

Semoga bermanfaat :3

Sumber : https://www.nginx.com

Share on

Iqbal
WRITTEN BY
Iqbal
I am just a man, not superhuman!