Print
카테고리: [ Nginx ]
조회수: 145

1. 개요

우분투 머신에 Nginx를 설치하는 방법


2. apt install nginx

$ sudo apt install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libgd3 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libxslt1.1
  nginx-common nginx-core
Suggested packages:
  libgd-tools fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
  libgd3 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libxslt1.1
  nginx nginx-common nginx-core
0 upgraded, 9 newly installed, 0 to remove and 44 not upgraded.
Need to get 819 kB of archives.
After this operation, 3021 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Y를 입력하여 설치를 계속한다.

Setting up libgd3:arm64 (2.2.5-5.2ubuntu2.1) ...
Setting up libxslt1.1:arm64 (1.1.34-4) ...
Setting up libnginx-mod-mail (1.18.0-0ubuntu1.3) ...
Setting up libnginx-mod-http-image-filter (1.18.0-0ubuntu1.3) ...
Setting up libnginx-mod-stream (1.18.0-0ubuntu1.3) ...
Setting up libnginx-mod-http-xslt-filter (1.18.0-0ubuntu1.3) ...
Setting up nginx-core (1.18.0-0ubuntu1.3) ...
Setting up nginx (1.18.0-0ubuntu1.3) ...
Processing triggers for ufw (0.36-6ubuntu1) ...
Processing triggers for systemd (245.4-4ubuntu3.15) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...

설치가 완료되었다.


3. Nginx 기동

$ sudo service start nginx
start: unrecognized service

메시지가 이상하다.

$ ps -ef | grep nginx
root       77090       1  0 01:28 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data   77091   77090  0 01:28 ?        00:00:00 nginx: worker process
www-data   77092   77090  0 01:28 ?        00:00:00 nginx: worker process
ubuntu     77270   76647  0 01:32 pts/0    00:00:00 grep --color=auto nginx
$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-05-02 01:28:46 UTC; 3min 56s ago
       Docs: man:nginx(8)
   Main PID: 77090 (nginx)
      Tasks: 3 (limit: 1081)
     Memory: 6.2M
     CGroup: /system.slice/nginx.service
             ├─77090 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─77091 nginx: worker process
             └─77092 nginx: worker process

May 02 01:28:46 ip-10-21-130-127 systemd[1]: Starting A high performance web server and a reverse proxy server...
May 02 01:28:46 ip-10-21-130-127 systemd[1]: Started A high performance web server and a reverse proxy server.

기동은 된 것 같다. 페이지를 호출해본다.

$ curl http://127.0.0.1:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

4. 설정 파일

설정 파일은 /etc/nginx 아래에 있다.