[Linux Server] Nginx 설치 하기 - CentOS 6.7 소스 컴파일 설치

2020. 1. 22. 00:21·Linux Server

패키지 설치 대신 소스 설치 해야 하는 이유 ?

여러가지 이유가 있지만, 실 업무를 진행하며 느낀 개인적인 견해로는....

 

1. 버전 변경에 용이)
apps 전용 폴더 설정 후, S-링크만 연결하여주면 기존 버전 변동없이 바로 버전 up/down 가능. 
(ex: ln -s ~/apps/nginx-1.0.1 ~/apps/nginx   <-->  ln -s ~/apps/nginx-1.1.1 ~/apps/nginx)

 

2. 루트 권한 없이도 유저 or 그룹 단위로 엔지니어링 가능)
패키지 설치와 달리 지정한 폴더로 설치되기 때문에 root 권한이 필요하지 않음.

 

3. 새로운 환경의 서버로 이동할 경우 복구가 용이)
초기 설치한 옵션을 init.sh로 만들면 쉽게 새로운 서버에서 손쉽고 빠르게 재 설정 가능.

 

4. 의존성 문제 크게 없음.

 

1. 설치 전 준비 사항

#pcre 라이브러리 설치
sudo yum -y install pcre*

#gzip 압축을 사용하기 위해서 설치
sudo yum -y install zlib zlib-devel

#open ssl 설치
sudo yum -y install openssl openssl-devel

 

 

2. nginx 다운로드

cd /home1/username/stage
wget https://nginx.org/download/nginx-1.12.0.tar.gz
tar -xvzf nginx-1.12.0.tar.gz

 

3. nginx 컴파일 설치

cd /home1/username/stage/nginx-1.12.0

#NginX 폴더안에 있는 내용 컴파일 
sudo ./configure --prefix=/home1/username/apps/nginx-1.12.0 --user=username --group=username --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module

#make, install
sudo make
sudo make install

#심볼릭 링크 연결
ln -s /home1/username/apps/nginx-1.12.0 /home1/username/apps/nginx

 컴파일 옵션 설명

  • --prefix=경로 : 컴파일후 설치되는 경로
  • --user=사용자계정 : 엔진엑스 작업자 프로세스를 실행하기 위한 기본 사용자 계정 (이설정은 환경설정 파일에 user 지시어를 생략했을 경우에만 적용된다.)
  • --group=그룹 : 엔진엑스 작업자 프로세스를 실행하기 위한 기본 사용자 그룹 (이설정은 환경설정 파일에 group 지시어를 생략했을 경우에만 적용된다.)
  • --width-http_realip_module : 요청 헤데 데이터로부터 실제 IP 주소를 읽어 내는 Real IP 모듈
  • --with-http_stub_status_module : 서버 통계와 정보페이지를 생성하는 스터브 상태
  • 기타 컴파일시 옵션 추가 할 수 있음.

4. nginx conf 수정

여러 사이트를 동시에 nginx에 올려야  할 경우,
conf/nginx.conf를 직접 수정하기 보다는 conf를 각각 작성하여 include 하는 방식을 권장 합니다

  • sites-available 디렉토리에 사이트별로 각각 conf 작성.
  • sites-enabled 디렉토리에 사용할 사이트를 심볼릭링크로 등록.
  • nginx.conf에서 sites-enabled디렉토리를 include.

 

sites-available 디렉토리에 사이트별로 각각 conf 작성.

mkdir -p ~/apps/nginx/conf/sites-available

cd ~/apps/nginx/conf/sites-available

vi test.com.conf
#내용 작성
#test.com.conf
server {
        listen       80 default_server;
        listen       localhost default_server;

		#root 변경!
        location / {
            root   /home1/username/apps/nginx/html/path/to/project;
            index  index.php index.html index.htm;
                try_files $uri $uri/ /index.php?$query_string;
        }
        
        #php-fpm 연동할 경우 아래 내용도 설정.
        location ~ \.php$ {
                root    /home1/username/apps/nginx/html/path/to/project;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include         fastcgi_params;
        }
}

 

sites-enabled 디렉토리에 사용할 사이트를 심볼릭링크로 등록.

mkdir -p ~/apps/nginx/conf/sites-enabled

cd ~/apps/nginx/conf/sites-enabled

ln -s ../sites-enabled/test.com.conf

 

nginx.conf에서 sites-enabled디렉토리를 include.

#nginx conf 수정
cd /home1/username/apps/nginx/conf
vi nginx.conf

...
#user  nobody;
worker_processes  auto;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

 #   access_log  logs/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    server_tokens       off;
    keepalive_timeout   65;
    types_hash_max_size 2048;

        include /home1/username/apps/nginx/conf/sites-enabled/*;
}

5. nginx 실행

#nginx 실행
sudo /home1/username/apps/nginx/sbin/nginx

#nginx 중지
sudo /home1/username/apps/nginx/sbin/nginx -s stop

#nginx conf reload
sudo /home1/username/apps/nginx/sbin/nginx -s reload

 

 

6. ip주소로 접속하여 nginx 구동 확인.

'Linux Server' 카테고리의 다른 글

[Linux Server] php 소스 설치 하기 - CentOS 6.7 소스 컴파일 설치  (0) 2020.02.05
[Linux Server] CentOS php composer 설치  (0) 2020.01.22
'Linux Server' 카테고리의 다른 글
  • [Linux Server] php 소스 설치 하기 - CentOS 6.7 소스 컴파일 설치
  • [Linux Server] CentOS php composer 설치
DAMAT
DAMAT
Computer Science Engineer를 위한 tiStory
  • DAMAT
    Damat - Idea Factory
    DAMAT
  • 전체
    오늘
    어제
    • 분류 전체보기 (23)
      • Bigdata Engineering (14)
        • 빅데이터 플랫폼 R&D (1)
      • System Engineering (2)
      • Linux Server (3)
      • 프로그래밍 (0)
      • 교육 (1)
        • 문제 (1)
      • 코딩테스트 기록지 (2)
        • Python (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    주키퍼 cli
    주키퍼 명령어
    kafka cli
    mysql 보관기관 설정
    zookeeper 명령어
    db binlog
    python데몬
    python 소켓 프로그래밍
    파이썬 소켓통신
    hadoop이란
    zookeeper cli
    python 소켓통신
    gitlab 버전
    빅데이터 모니터링
    activemq 모니터링
    presto 메모리 설정
    gitlab 패치
    파이썬 소켓
    리소스매니저
    kafka 명령어
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.4
DAMAT
[Linux Server] Nginx 설치 하기 - CentOS 6.7 소스 컴파일 설치
상단으로

티스토리툴바