서버에 nginx 설치하기

young·2021년 9월 26일
0

*사용환경 : CentOs 7

1. user 및 디렉토리 생성

$ useradd nginx
$ mkdir -p /app/nginx/src /applog/nx_log

2. nginx 설치 파일 다운로드 (설치)

  • 파일 경로 지정 (/app/nginx/src)
  • stable version의 tar파일 다운로드
  • ftp로 파일 수동 업로드 (서버에서 직접 다운로드 불가)
  • 압축 해제

3. nginx 설치

$ sudo chown -R root:root /app/nginx
$ cd /app/nginx/src/nginx-1.18.0
$ ./configure --prefix=/app/nginx/nginx118 --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --http-scgi-temp-path=/var/lib/nginx/scgi --http-log-path=/applog/nx_log/access.log --error-log-path=/applog/nx_log/error.log --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module
$ sudo make && sudo make install
#configuration option

--prefix=PATH                   #set installation prefix
--pid-path=PATH                 #set nginx.pid pathname
--lock-path=PATH                #set nginx.lock pathname
--user=USER                     #set non-privileged user for worker processes
--group=USER                    #set non-privileged group for worker processes
--http-client-body-temp-path=/var/lib/nginx/body    #set path to store http client request body temporary files
--http-proxy-temp-path=/var/lib/nginx/proxy         #set path to store http proxy temporary files
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi     #set path to store http fastcgi temporary files
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi         #set path to store http uwsgi temporary files
--http-scgi-temp-path=/var/lib/nginx/scgi           #set path to store http scgi temporary files
--http-log-path=PATH            #set http access log pathname
--error-log-path=PATH           #set error log pathname
--with-http_ssl_module          #enable ngx_http_ssl_module
--with-http_realip_module       #enable ngx_http_realip_module
--with-http_stub_status_module  #enable ngx_http_stub_status_module

4. nginx 실행 권한 설정

$ sudo chown -R nginx:nginx /app/nginx /applog/nx_log
$ cd /nginx/nginx118/sbin
$ sudo chown root:sys nginx
$ sudo chmod ug+s nginx

5. nginx configuration 설정

$ sudo vi /app/nginx/nginx118/conf/nginx.conf

6. nginx 서비스 등록

$ sudo mkdir -p /var/lib/nginx/body
$ sudo vi /etc/systemd/system/nginx.service
$ sudo systemctl enable nginx.service
$ sudo systemctl start nginx.service
#nginx.service

[Unit]
Description=The NGINX HTTP and reserve proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/app/nginx/nginx118/sbin/nginx -t
ExecStart=/app/nginx/nginx118/sbin/nginx
ExecReload=/app/nginx/nginx118/sbin/nginx -s reload
ExecStop=/app/nginx/nginx118/sbin/nginx -s stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

0개의 댓글