Instalasi Nginx Debian 12

Dari Dokumentasi Robie
Loncat ke navigasi Loncat ke pencarian

Install nginx dengan mengetikkan perintah

root@nginx:~# apt install nginx (enter)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  nginx-common
Suggested packages:
  fcgiwrap nginx-doc
The following NEW packages will be installed:
  nginx nginx-common
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 640 kB of archives.
After this operation, 1696 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y (enter)
Get:1 http://deb.debian.org/debian bookworm/main amd64 nginx-common all 1.22.1-9 [112 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 nginx amd64 1.22.1-9 [527 kB]
Fetched 640 kB in 0s (2491 kB/s)
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 19463 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.22.1-9_all.deb ...
Unpacking nginx-common (1.22.1-9) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.22.1-9_amd64.deb ...
Unpacking nginx (1.22.1-9) ...
Setting up nginx-common (1.22.1-9) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service -> /lib/systemd/system/nginx.service.
Setting up nginx (1.22.1-9) ...
Upgrading binary: nginx.
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for ufw (0.36.2-1) ...
root@nginx:~# 

Cek / Test

Restart nginx

root@nginx:~# systemctl restart nginx (enter)
root@nginx:~# systemctl status nginx (enter)
* nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Tue 2024-09-03 01:48:21 UTC; 35s ago
       Docs: man:nginx(8)
    Process: 5207 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exit>
    Process: 5209 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, statu>
   Main PID: 5210 (nginx)
      Tasks: 2 (limit: 38314)
     Memory: 1.7M
        CPU: 5ms
     CGroup: /system.slice/nginx.service
             |-5210 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             `-5211 "nginx: worker process" 

Sep 03 01:48:21 nginx systemd[1]: Starting nginx.service - A high performance web server and a r>
Sep 03 01:48:21 nginx systemd[1]: Started nginx.service - A high performance web server and a re>
...skipping...
* nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running) since Tue 2024-09-03 01:48:21 UTC; 35s ago
       Docs: man:nginx(8)
    Process: 5207 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exit>
    Process: 5209 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, statu>
   Main PID: 5210 (nginx)
      Tasks: 2 (limit: 38314)
     Memory: 1.7M
        CPU: 5ms
     CGroup: /system.slice/nginx.service
             |-5210 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             `-5211 "nginx: worker process"

Sep 03 01:48:21 nginx systemd[1]: Starting nginx.service - A high performance web server and a r>
Sep 03 01:48:21 nginx systemd[1]: Started nginx.service - A high performance web server and a re>
~
~
lines 1-16/16 (END) (tekan kombinasi tombol ctrl + c untuk keluar dari tampilan ini)
^C
root@nginx:~# ^C
root@nginx:~# 

Cek IP Address Server dengan mengetikkan perintah

root@Ngin-X:~# ip a (enter)
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0@if58: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 42:92:d2:25:49:58 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.20.9 (ip address server)/24 brd 192.168.20.255 scope global dynamic eth0
       valid_lft 1566sec preferred_lft 1566sec
    inet6 fe80::4092:d2ff:fe25:4958/64 scope link 
       valid_lft forever preferred_lft forever
root@Ngin-X:~#

akses melalui web

http://192.168.20.9

akan keluar kata-kata

Welcome to nginx!
Gagal membuat miniatur: Berkas tak ditemukan


Konfigurasi Default

Folder HTML default

root /usr/share/nginx/html;

Konfigurasi nginx

/etc/nginx/sites-enabled/default
chmod -Rf 755 /usr/share/nginx
chown -Rf nobody.nogroup /usr/share/nginx

Untuk mengubah document root supaya tidak bentrok, ubah /etc/nginx/sites-enabled/default

root /var/www/html;