nginx原始碼安裝

發表於2020-06-14

nginx原始碼安裝

1、前提準備

準備主機

主機名稱 IP 作用
client 192.168.7.11 nginx主機

下載nginx軟體包:http://nginx.org/download/nginx-1.14.0.tar.gz

關閉防火牆和selinux

# systemctl stop firewalld
# systemctl disable firewalld
# setent

下載外掛並且建立nginx使用者

#  yum -y install pcre-devel openssl openssl-devel gd-devel
#  yum -y groups mark install 'Development Tools' 
#  useradd -r -M -s /sbin/nologin nginx
//建立日誌目錄
# mkdir -p /var/log/nginx
# chown -R nginx.nginx /var/log/nginx

2、安裝

下載並且解壓nginx

# wget http://nginx.org/download/nginx-1.14.0.tar.gz
# tar -xf nginx-1.14.0.tar.gz
nginx-1.14.0.tar.gz nginx-1.14.0

進入安裝目錄進行編譯安裝

# pwd
/root/nginx-1.14.0
# ./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \ 
--with-debug \ 
--with-http_ssl_module \
--with-http_realip_module \ 
--with-http_image_filter_module \ 
--with-http_gunzip_module \ 
--with-http_gzip_static_module \ 
--with-http_stub_status_module \ 
--http-log-path=/var/log/nginx/access.log \ 
--error-log-path=/var/log/nginx/error.log

#  make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install 

檢視並且啟動

# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# cd /usr/local/nginx/sbin/
# ls
nginx 

3、nginx後續配置

新增環境變數

# echo "export PATH=/usr/local/nginx/sbin/:$PATH" > /etc/profile.d/nginx.sh
#  /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# nginx -s start
# ss -antl
State       Recv-Q Send-Q               Local Address:Port                              Peer Address:Port              
LISTEN      0      128                              *:80                                           *:*                  
LISTEN      0      128                              *:22                                           *:*                  
LISTEN      0      100                      127.0.0.1:25                                           *:*                  
LISTEN      0      128                             :::22                                          :::*                  
LISTEN      0      100                            ::1:25                                          :::*       

相關文章