반응형

안녕하세요. 가야태자 @talkit 입니다.

궁극적으로 하려고 하는 것은 Mattermost라는 Slack 대체 프로그램에 TLS 기반의 SSL을 도입하게 하는 것입니다.

그전에 NGINX를 잘 몰라서 설치해보고, SSL을 어떻게 구성하는지를 좀 알아보고 다시 Mattermost를 손을 대야 할 것 같습니다.

웹서버는?

웹서버는 간단하게 정의하자면 웹을 서비스하는 서버 입니다. 저희가 http 또는 https로 시작하는 주소를 입력하면 브라우져에서 여러 화면들을 확인하게 되는데, 그 주소에 웹서버가 있기 때문입니다.

그런데, 저는 Apache Web Server 주로 사용하는 사람입니다. 하지만, 그렇다고, 블로그에 아파치를 설치하는 방법을 적은 적이 없네요 ^^ 앞으로는 적도록 하겠습니다.

https://httpd.apache.org/

아파치 웹서버는 위 URL에서 정보를 확인하고 다운로드 할 수 있습니다.

물론 Ubuntu에서 기본 패키지로 제공하기 때문에 금방 설치할 수 있습니다.

이번에 적으려고 하는 NGINX도 웹서버의 일종입니다. Apache 보다는 좀 더 뒤에 나온 제품이어서 좀 더 신선한 기능들을 제공하긴 하지만, 서로 경쟁 관계여서 요즘은 NGINX가 좀 더 점유율을 가져가고 있다고 알고 있습니다. ^^ 서로를 보고 보완을 하고 있는 것으로 알고 있습니다.

W3Techs - extensive and reliable web technology surveys 출처 : https://w3techs.com/

위에서 보시다 싶이 NGIX가 1.1% 정도 우위를 점유하고 있습니다.

NGINX의 공식 웹사이트는 https://nginx.org/en/ 에서 확인할 수 있습니다.

우리는 우분투 리눅스에 오늘 NGINX를 설치할 것입니다. ^^

우분투 리눅스 설치.

리눅스/Linux VMWARE에 우분투/Ubuntu 20.04 설치하기/Install https://talkit.tistory.com/677

리눅스/Linux VMWARE에 우분투/Ubuntu 18.04 설치하기/Install https://talkit.tistory.com/637

위두 글을 이용해서 VMWARE에 리눅스를 설치 하십시오.

Putty 로 리눅스에 접속하기

[무료소프트웨어] 무료 보안쉘 클라이언트 PuTTY 최신 버전 다운로드 및 설치하기. How to Install the latest version PuTTY that is free Secure Shell Client. https://talkit.tistory.com/674

리눅스/Linux 오라클 VPS에 접속해보자. How to connect to free VPS on Oracle Cloud. https://talkit.tistory.com/673

리눅스/Linux SSH를 통해서 VMWARE Linux에 접속해보자. How to connect to Linux on VMWARE via SSH https://talkit.tistory.com/688

리눅스에 접속하시는 방법은 위 글들에서 설명해 두었습니다. 참고해서 접속하시면 될 것 같습니다.

리눅스에 NGINX 설치

저는 계속 Putty러 접속을 합니다.

여러분들이 VMWARE에 우분투를 설치하셨거나, 우분투 리눅스 VPS를 하나 가지고 계시거나 하다는 전제 하에서 이 글은 시작 하고 있습니다.

리눅스에 접속하기

서버에 우선 접속하십시오.

Putty를 여시고 저기 주소에 입력하시거나 아래에 있는 저장된 세션에서 선택해서 접속 하시면 됩니다.

login as: talkit
talkit@192.168.0.27's password:
Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 5.15.0-56-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 updates can be applied immediately.

Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Thu Dec 29 23:51:08 2022 from 192.168.0.3
talkit@ubuntu:~$ ps -ef | grep nginx
talkit      2021    2007  0 23:50 pts/0    00:00:00 grep --color=auto nginx
talkit@ubuntu:~$

저는 잘 접속이 되었구요.

접속해서 ps로 nginx가 없는 것 까지 확인 했습니다. 제가 Mattermost를 설치하면서 nginx도 설치 했거든요 ^^

nginx 설치 이전으로 VMWARE파일을 돌려 놨습니다.

NGINX 설치하기

그 다음 과정을 계속 진행 하겠습니다.

sudo apt update

위 명령어는 옵셔널 이긴 하지만 한번씩 해주는 것이 좋습니다.

sudo apt install nginx

NGINX 설치는 정말 간단합니다. ^^

 sudo apt install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream
  nginx-common nginx-core
Suggested packages:
  fcgiwrap nginx-doc
The following NEW packages will be installed:
  libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream
  nginx nginx-common nginx-core
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 605 kB of archives.
After this operation, 2,141 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 nginx-common all 1.18.0-0ubuntu1.4                                                                                                                                                                                                                        [37.7 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-http-image-filter amd6                                                                                                                                                                                                                       4 1.18.0-0ubuntu1.4 [14.8 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-http-xslt-filter amd64                                                                                                                                                                                                                        1.18.0-0ubuntu1.4 [13.0 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-mail amd64 1.18.0-0ubu                                                                                                                                                                                                                       ntu1.4 [42.9 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libnginx-mod-stream amd64 1.18.0-0u                                                                                                                                                                                                                       buntu1.4 [67.4 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 nginx-core amd64 1.18.0-0ubuntu1.4                                                                                                                                                                                                                        [425 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 nginx all 1.18.0-0ubuntu1.4 [3,620                                                                                                                                                                                                                        B]
Fetched 605 kB in 2s (293 kB/s)
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 160070 files and directories currently installed.)
Preparing to unpack .../0-nginx-common_1.18.0-0ubuntu1.4_all.deb ...
Unpacking nginx-common (1.18.0-0ubuntu1.4) ...
Selecting previously unselected package libnginx-mod-http-image-filter.
Preparing to unpack .../1-libnginx-mod-http-image-filter_1.18.0-0ubuntu1.4_amd64.deb ...
Unpacking libnginx-mod-http-image-filter (1.18.0-0ubuntu1.4) ...
Selecting previously unselected package libnginx-mod-http-xslt-filter.
Preparing to unpack .../2-libnginx-mod-http-xslt-filter_1.18.0-0ubuntu1.4_amd64.deb ...
Unpacking libnginx-mod-http-xslt-filter (1.18.0-0ubuntu1.4) ...
Selecting previously unselected package libnginx-mod-mail.
Preparing to unpack .../3-libnginx-mod-mail_1.18.0-0ubuntu1.4_amd64.deb ...
Unpacking libnginx-mod-mail (1.18.0-0ubuntu1.4) ...
Selecting previously unselected package libnginx-mod-stream.
Preparing to unpack .../4-libnginx-mod-stream_1.18.0-0ubuntu1.4_amd64.deb ...
Unpacking libnginx-mod-stream (1.18.0-0ubuntu1.4) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../5-nginx-core_1.18.0-0ubuntu1.4_amd64.deb ...
Unpacking nginx-core (1.18.0-0ubuntu1.4) ...
Selecting previously unselected package nginx.
Preparing to unpack .../6-nginx_1.18.0-0ubuntu1.4_all.deb ...
Unpacking nginx (1.18.0-0ubuntu1.4) ...
Setting up nginx-common (1.18.0-0ubuntu1.4) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.                                                                                                                                                                                                                       service.
Setting up libnginx-mod-http-xslt-filter (1.18.0-0ubuntu1.4) ...
Setting up libnginx-mod-mail (1.18.0-0ubuntu1.4) ...
Setting up libnginx-mod-http-image-filter (1.18.0-0ubuntu1.4) ...
Setting up libnginx-mod-stream (1.18.0-0ubuntu1.4) ...
Setting up nginx-core (1.18.0-0ubuntu1.4) ...
Setting up nginx (1.18.0-0ubuntu1.4) ...
Processing triggers for systemd (245.4-4ubuntu3.19) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for ufw (0.36-6ubuntu1) ...
talkit@ubuntu:~$

중간에 Y 한번만 눌러 주시면 됩니다.

 sudo systemctl status nginx
● 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 Sat 2022-12-31 23:56:28 PST; 51s ago
       Docs: man:nginx(8)
   Main PID: 2701 (nginx)
      Tasks: 17 (limit: 19071)
     Memory: 13.8M
     CGroup: /system.slice/nginx.service
             ├─2701 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─2702 nginx: worker process
             ├─2703 nginx: worker process
             ├─2704 nginx: worker process
             ├─2705 nginx: worker process
             ├─2706 nginx: worker process
             ├─2707 nginx: worker process
             ├─2708 nginx: worker process
             ├─2709 nginx: worker process
             ├─2710 nginx: worker process
             ├─2711 nginx: worker process
             ├─2712 nginx: worker process
             ├─2713 nginx: worker process
             ├─2714 nginx: worker process
             ├─2715 nginx: worker process
             ├─2716 nginx: worker process
             └─2717 nginx: worker process

Dec 31 23:56:28 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 31 23:56:28 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.

리눅스 서비스를 확인하면 이미 nginx가 활성화 되어 있는 상태 입니다. ^^

방화벽 설정 - 생략

방화벽 관련 설정도 있지만 방화벽 설정은 안해서 ^^

웹서버에 브라우져로 접속해 보기

웹서버가 켜져 있는걸 확인 했으니까 브라우져로 접속을 해보겠습니다.

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

잘 설치 되었다고 뜨네요 ^^

기본적으로 여기까지하면 웹서버가 설치 되었습니다. 

다음에는 웹서버의 웹 문서들을 어디에 놓을 건지에 대해서 말씀 드리겠습니다. 

감사합니다. 

 

 

반응형
반응형
1호점에서 가져왔습니다.

우선 APM 설치에 관한 이야기는 인터넷 상에 너무나 많이 나와 있음으로 여기서는 다루지 않음을 밝혀 둔다

우선 APM 즉 Apache PHP MySQL을 운영하고자하는 두대의 서버에 모두 설치한다.

DB 서버를 사용하고자 하는 곳을 정하고 DNS를 설정한다.

웹서비스를 하고자 하는 서버를

www.yourdomain.com 과 yourdomain.com

을 할당하고

DB 서버로 사용하고자하는 서버를

db.yourdomain.com 을 할당한다.

내가 APM을 두대다 설치하라고 한 이유는 간단하다.

우선 한대는 MySQL 서버를 운영할 필요가 없지만 MySQL의 라이버러리와 클라이언트가 필요하다

그리고, 한대는 Apache + PHP가 필요 없지만

요즘 내가 mysql 클라이언트로 MySQL을 운영할 자신이 없기 때문이다.

그래서 phpMyAdmin을 설치하기 위해서는 APM 환경이 돌아가야한다.

그래서 운영하고자 하는서버 두대 모두 APM을 설치하라고 한 것이다.

그럼 설치는 끝났다고 생각하겠다.

그리고, Apache(http) 데몬과 MySQL 데모인 각각의 서버에 제대로 떠 있다고 생각하겠다.

그럼 아까 말한대로 phpMyAdmin을 db.yourdomain.com 서버에

http://www.phpmyadmin.net/

를 방문해서 다운 최신 버전으로 받은 후 설치해라.

설치라고 해야 간단하다.

우선 압축 파일을 받아서

계정에 올리고 웹서비스를 할 수 있는 곳의 root로 옮기고

tar xzvfp phpMyAdmin.version.tar.gz

이렇게하면 풀리는 모습이 보이면서 압축이 풀릴 것이다.

그리고

mv phpMyAdmin.version phpMyAdmin

해서 디렉토리 명을 원하는대로 변경한다.

나는 프로젝트 자체를 존중하기 때문에 프로젝트 명을 디렉토리명으로 쓴다. 버전 까지 쓰고 싶지만 웹에서 접근할때 좀 힘들어서 ^^;;

cd phpMyAdmin

vi config.inc.php

최근 버전 부터 아래 옵션이 생겼다.

$cfgPmaAbsoluteUri = ' http://db.yourdomain.com/yourdir/phpMyAdmin/';

(yourdir)은 없다면 적지 않아도 된다.

그러니깐 이 옵션은 phpMyAdmin을 서비스할 완벽한 URL을 적어 두는 곳이다.

죽 내려보면

$cfgServers[$i]['host'] = 'localhost'; // MySQL hostname


$cfgServers[$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)?

여기서 잠깐 auth_type은 원래 config라고 되어 있다 MySQL 자체의 인증을 사용하기 위해서 나는 http를 선택했다.


$cfgServers[$i]['user'] = 'youruser'; // MySQL user
$cfgServers[$i]['password'] = 'yourpass'; // MySQL password (only needed

위와 같은 옵션들이 존재할 것이다.

저것을 여러분들에게 맞게 변경해라.

그리고 저장하고 vi를 닫아라.

저장했으면 이제 웹브라우져에서

http://db.yourdomian.com/phpMyAdmin/

에 접근해 보자

그러면 ID와 PW를 묻는다.

이때 root 아이디와 PW를 넣고 접근한다.

지금 부터 우리는 계정을 생성할 것이기 때문이다.

phpMyAdmin에 접근 했으면

이제 mysql 데이타 베이스에 접근 해라.

그리고 user 테이블로 이동한다.

그리고 추가 버튼을 누른다.

Host 에 www.yourdomain.com 의 아이피를 적어라

IP주소는 nslookup www.yourdomain.com

이라고 하면 알 수 있다.

그리고 userid에 당신이 원하는 아이이들 적고

password에 함수를 선택한다 PASSWORD 함수를 선택하고 옆에 빈칸에 자신이 원하는 비밀번호를 적는다.

그리고, 보통은 아래의 모든 값을 N으로 하고 db를 설정하는 것이 좋다

하지만, 나는 원격 root 성격의 아이디를 만들겠다.

그래서 아래의 값들을 모두 Y를 선택하기를 원한다.

그럼 모두 선택했으면 실행 버튼을 눌러서

아이디를 생성한다.

이대로 두면 MySQL은 방금 생성한 아이디를 제대로 인식하지 못한다.

그래서 셀렉트 바에서 - 를 선택해라.

그리고, 옆 화면을 주시하면 MySQL 재시동 이라는 링크가 보일 것이다.

클릭해라.

그럼 이제 부터 www.yourdomain.com에서 db.yourdomain.com의 MySQL 데이타 베이스에 접근이 가능해 졌다.

그럼 이제 web 서버를 설정하러 가보자

웹서버에는 Apache만 구동한다. MySQL은 구동하지 않는다.

이유는 간단하다. 원격으로 DB 서버를 구성해 두었기 때문이다.

MySQL은 클라이언트로만 사용할 것이다.

그럼 아까 받아 둔 phpMyAdmin을 역시 www.yourdomain.com의 서비스 디렉토리에 설치한다.

압축을 풀고 디렉토리를 변경하는 과정 까지는 같고 콘피그 파일을 설정하는 방법이 조금 다르다.

다음과 같이 따라하면 된다.

vi config.inc.php

$cfgPmaAbsoluteUri = ' http://www.yourdomain.com/yourdir/phpMyAdmin/';

(yourdir)은 없다면 적지 않아도 된다.

그러니깐 이 옵션은 phpMyAdmin을 서비스할 완벽한 URL을 적어 두는 곳이다.

죽 내려보면

$cfgServers[$i]['host'] = 'db.yourdomain.com or dbs.erv.er'.sip'; // MySQL hostname

여기서 여러분은 눈치가 빠른 사용자라면 눈치 챌 것이다.

php 등에서 mysql 접속함수를 쓰면서 다음과 같이 해 줘야 된다는 것을

mysql_connect("db.yourdomain.com or db.yourdomain.com or dbs.erv.er'.sip", "yourid", "yourpw");

이렇게 말이다. 이것 외에는 다른 점이 없다.


$cfgServers[$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)?

여기서 잠깐 auth_type은 원래 config라고 되어 있다 MySQL 자체의 인증을 사용하기 위해서 나는 http를 선택했다.


$cfgServers[$i]['user'] = 'youruser'; // MySQL user
$cfgServers[$i]['password'] = 'yourpass'; // MySQL password (only needed

여기서 아까 우리가 생성한 원격서버의 root 계정의 정보를 적어라

당신이 만든 아이디와 패스워드를 말이다. db 서버의 root 계정이 아니고 새로 만든 아이디를 의미한다.

그리고 저장하고 vi를 닫아라.

저장했으면 이제 웹브라우져에서

http://www.yourdomian.com/phpMyAdmin/

저렇게 접근하고 아까 적은 아이디와 패스워드를 넣으면 db.yourdomain.com 에서 본 것과 동일한 환경이 나타날 것이다.

여기까지 끝냈으면 보안을 위해서 일단, db.yourdomain.com의 Apache 서버는 내려라 MySQL은 두고 말이다.

그리고 우리는 이제 www 도메인만 사용한다.

http://www.yourdomian.com/phpMyAdmin/

이곳에 접근해서 원격 슈퍼유져 아이디는 당신만이 기억하고 또는 당신 보스와 함께 하지만, 앞으로 접근할 다른 사람들의 아이디는 db와 성격에 맞게 잘 만들어서 써야한다.

이부분은 더이상 설명하지 않겠다.

이렇게 하면 원격으로 Web 서버와 DB서버를 분리해서 운영할 수 있다.

허접한 글이긴 하지만 여러분들께 많은 도움이 되었으면 하는 바램이다.
반응형

+ Recent posts