본문 바로가기
서버/Nginx

Nginx 소스 컴파일 설치

by WYYOON 2023. 2. 6.
728x90
반응형
SMALL

 

SMALL

OS : CentOS7

Nginx version : nginx-1.16.1

 

 

#필수 라이브러리 설치
yum -y install gcc* make libtool-ltdl-devel openssl-devel pcre-devel ncurses-devel libxml2-devel bzip2-devel curl-devel gdbm-devel libjpeg-devel libpng-devel freetype-devel krb5-devel flex icu libicu libicu-devel gd gd-devel wget gzip libxslt-devel cmake ncurses ncurses-devel bison gnutls-devel

 

# Nginx user 생성
useradd --shell /sbin/nologin nginx

 

#Nginx 소스 설치
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--sbin-path=/usr/local/nginx/sbin/nginx \
--lock-path=/usr/local/nginx/run/nginx.lock \
--pid-path=/usr/local/nginx/run/nginx.pid \
--http-client-body-temp-path=/usr/local/nginx/client_body_temp \
--http-proxy-temp-path=/usr/local/nginx/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/scgi_temp \
--http-log-path=/usr/local/nginx/logs/access.log \
--error-log-path=/usr/local/nginx/logs/error.log \
--with-http_addition_module \
--with-http_degradation_module \
--with-http_flv_module \
--with-http_image_filter_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_realip_module \
--with-http_xslt_module \
--with-http_dav_module \
--with-http_auth_request_module \

--with-http_v2_module \
--user=nginx \
--group=nginx

 

make && make install

 

 

#nginx 리부팅시 자동 ON

1. systemctl을 이용하는 방법 2. init.d에 등록하는 방법
vi /lib/systemd/system/nginx.service  vi /etc/rc.d/init.d/nginx
[Unit] 
Description=The NGINX HTTP and reverse proxy server 
After=syslog.target network.target remote-fs.target nss-lookup.target 

[Service] 
Type=forking 
PIDFile=/opt/nginx/run/nginx.pid 
ExecStartPre=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf 
ExecStart=/opt/nginx/sbin/nginx 
ExecReload=/opt/nginx/sbin/nginx -s reload 
ExecStop=/opt/nginx/sbin/nginx -s stop 
PrivateTmp=true 

[Install] 
WantedBy=multi-user.target 
#!/bin/sh 

# nginx - this script starts and stops the nginx daemin 

# chkconfig: - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
# proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config: /opt/nginx/conf/nginx.conf 
# pidfile: /var/run/nginx.pid 

# Source function library.
. /etc/rc.d/init.d/functions 

# Source networking configuration. 
. /etc/sysconfig/network 

# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0 

nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx) 

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf

lockfile=/var/lock/subsys/nginx 

start() { 
[ -x $nginx ] || exit 5 
[ -f $NGINX_CONF_FILE ] || exit 6 
echo -n $"Starting $prog: " 
daemon $nginx -c $NGINX_CONF_FILE 
retval=$? 
echo 
[ $retval -eq 0 ] && touch $lockfile 
return $retval 


stop() { 
echo -n $"Stopping $prog: " 
killproc $prog -QUIT 
retval=$? 
echo 
[ $retval -eq 0 ] && rm -f $lockfile 
return $retval 


restart() { 
configtest || return $? 
stop 
start 


reload() { 
configtest || return $? 
echo -n $"Reloading $prog: " 
killproc $nginx -HUP 
RETVAL=$? 
echo 


force_reload() { 
restart 


configtest() { 
$nginx -t -c $NGINX_CONF_FILE 


rh_status() { 
status $prog 


rh_status_q() { 
rh_status >/dev/null 2>&1 


case "$1" in 
start) 
rh_status_q && exit 0 
$1 
;; 
stop) 
rh_status_q || exit 0 
$1 
;; 
restart|configtest) 
$1 
;; 
reload) 
rh_status_q || exit 7 
$1 
;; 
force-reload) 
force_reload 
;; 
status) 
rh_status 
;; 
condrestart|try-restart) 
rh_status_q || exit 0 
;; 
*) 
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
exit 2 
esac

# 재부팅시 실행되도록 설정 
systemctl enable nginx.service 
#실행 권한 변경
chmod +x /etc/rc.d/init.d/nginx




728x90
반응형
SMALL

'서버 > Nginx' 카테고리의 다른 글

Cloudflare 설정시 nginx real ip 남기기  (0) 2019.09.27