티스토리 뷰
[WEB Server/Linux] NGINX 수동 설치 및 HTTP/HTTPS + stats page 적용
74059 2023. 6. 22. 16:07CentOS에서 yum을 이용하지 않고 수동으로 설치합니다.
[설치 환경] CentOS7
1. NGINX 파일 설치 및 압축 풀기
NGINX 버전 1.16.1로 설치 진행했습니다. 아래 링크에서 버전 확인하고 설치하시면 될 것 같습니다.
http://nginx.org/en/download.html
nginx: download
nginx.org
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar xvfz nginx-1.16.1.tar.gz
2. HTTPS를 위한 self-signed SSL 인증서 만들기
# SSL 폴더 따로 만들어 생성
mkdir ssl
cd ssl
# Generate a unique private key (KEY)
openssl genrsa -out mydomain.key 2048
# Generating a Certificate Signing Request (CSR)
openssl req -new -key mydomain.key -out mydomain.csr
# Creating a Self-Signed Certificate (CRT)
openssl x509 -req -days 365 -in mydomain.csr -signkey mydomain.key -out mydomain.crt
# Append KEY and CRT to mydomain.pem
bash -c 'cat mydomain.key mydomain.crt >> /home/user/apps/ssl/mydomain.pem'
[참고]
genrsa: key를 RSA 알고리즘으로 만들려 함
2048: private key bit
3. NGINX config 파일 수정
nginx.conf 파일은 nginx-1.16.1/conf/nginx.conf에 있습니다.
HTTP
추가해주어야 할 부분: location /nginx_status
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /nginx_status {
stub_status;
allow 127.0.0.1;
allow {로컬 컴퓨터로도 보고싶다면 local ip도 추가해주세요.};
deny all;
}
}
HTTPS
수정해주어야 할 부분: ssl_certificate, ssl_certificate_key
위에서 만든 ssl 경로를 작성해주세요.
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /home/user/apps/ssl/mydomain.pem;
ssl_certificate_key /home/user/apps/ssl/mydomain.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
4. NGINX 설치
configure 파일은 nginx-1.16.1 아래에 있습니다.
cd /home/user/apps/nginx-1.16.1
./configure --prefix=/home/user/apps/nginx/nginx --user=user --with-http_ssl_module --with-http_stub_status_module
make && make install
[참고]
--with-http_ssl_module: https 사용하는 경우, 인증서 때문에 필수적으로 붙여주어야 함
--with-http_stub_status_module: nginx stats page 적용을 위한 옵션
5. NGINX 실행 데몬 권한 변경
cd /home/user/apps/nginx/nginx/sbin
sudo chown -R root:user ./nginx
sudo chmod 4777 ./nginx
[참고]
chown: 1024 아래의 포트는 소유권이 root여야만 포트 할당이 가능한 것 같습니다.
chmod: 실행 권한
6. 접속
http://{ip주소}, http://{ip주소}/nginx_status, https://{ip주소} 각각 접속하셔서 확인해보시면 됩니다. ip주소 확인은 아래 명령어를 통해 확인하실 수 있습니다.
hostname -i
틀린 부분에 대한 지적 환영입니다 :)
'Cloud Computing > WEB' 카테고리의 다른 글
[WEB Server/Linux] HAproxy 수동 설치 및 config 파일 구성 (1) | 2023.06.30 |
---|---|
[Python/WEB] 내가 만든 웹 페이지 서버에 배포하기 (3) Django를 uWSGI와 NGINX를 이용해 배포하기 (1) | 2023.06.29 |
- Total
- Today
- Yesterday
- loadBalancing
- 수동설치
- Error
- vi
- haproxy
- venv
- uwsgi
- Linux
- static서버
- dockerfile
- django
- PostgreSQL
- flask
- nginx
- redis
- 웹배포
- cache
- docker
- Python
- Database
- css적용
- vim
- 가상환경
- 일괄변경
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |