반응형
Linux에 설치
필수 패키지 설치
sudo apt-get update \
&& sudo apt-get install -y \
build-essential \
libssl-dev \
openssl
pcre 설치
- 참고 : https://www.pcre.org
APP='pcre-8.43' \
&& cd /home/ubuntu/app \
&& wget https://ftp.pcre.org/pub/pcre/$APP.tar.gz \
&& tar -xzvf $APP.tar.gz \
&& rm $APP.tar.gz
zlib 설치
- 참고 : http://zlib.net
APP='zlib-1.2.11' \
&& cd /home/ubuntu/app \
&& wget http://zlib.net/$APP.tar.gz \
&& tar -xzvf $APP.tar.gz \
&& rm $APP.tar.gz
nginx 설치
APP='nginx-1.17.1' \
&& cd /home/ubuntu/app \
&& wget http://nginx.org/download/$APP.tar.gz \
&& tar -xzvf $APP.tar.gz \
&& rm $APP.tar.gz \
&& mv $APP $APP-install
설정
APP='nginx-1.17.1' \
&& cd /home/ubuntu/app/$APP-install \
&& sudo ./configure \
--prefix=/home/ubuntu/app/$APP \
--with-pcre=/home/ubuntu/app/pcre-* \
--with-zlib=/home/ubuntu/app/zlib-* \
--with-http_ssl_module \
&& sudo make \
&& sudo make install \
&& cd /home/ubuntu/app \
&& ln -s -Tfs $APP nginx
환경변수 설정
sudo vi ~/.profile
export NGINX_HOME=/home/ubuntu/app/nginx
export PATH=$PATH:$NGINX_HOME/sbin
# sudo 권한으로 PATH 지정 명령어 수행할 수 있도록 설정
alias sudo='sudo env PATH=$PATH'
환경변수 설정 적용
source ~/.profile
실행 및 확인
sudo nginx \
&& curl localhost \
&& sudo nginx -s stop
참고
Docker로 설치
nginx.conf
- 경로 : ~/config/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '[$remote_addr][$time_iso8601][$status][$request][$http_referer][$http_user_agent]';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
location / {
root /home/nginx/deploy;
index index.html index.htm;
}
}
}
index.html
- 경로 : ~/deploy/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Hello World
</body>
</html>
docker-compose.yml
- 경로 : ~/docker-compose.yml
version: "3.3"
services:
nginx:
image: nginx:1.17.9
environment:
TZ: Asia/Seoul
ports:
- "80:80"
- "443:443"
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf
- ./deploy/:/home/nginx/deploy/
command:
- "/bin/sh"
- "-c"
- |
mkdir -p /home/nginx/logs
nginx -g 'daemon off;'
실행
docker-compose up
반응형
'Development > Nginx' 카테고리의 다른 글
[Nginx] Let's Encrypt로 SSL 설정(Docker) (0) | 2024.02.08 |
---|---|
[Nginx] Echo Module 사용하기 (0) | 2019.09.07 |
[Nginx] 설정 (0) | 2019.07.06 |