编译安装nginx

编译安装NGINX
1、安装依赖包
yum install -y gcc pcre-devel openssl-devel zlib-devel make
2、创建nginx用户
useradd nginx -s /sbin/nologin
3、解压安装包
cd /usr/local/src
tar xf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
4、编译安装nginx
./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module 
--with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

make && make install

5、配置文件信息
  nginx path prefix: "/apps/nginx"
  nginx binary file: "/apps/nginx/sbin/nginx"
  nginx modules path: "/apps/nginx/modules"
  nginx configuration prefix: "/apps/nginx/conf"
  nginx configuration file: "/apps/nginx/conf/nginx.conf"
  nginx pid file: "/apps/nginx/logs/nginx.pid"
  nginx error log file: "/apps/nginx/logs/error.log"
  nginx http access log file: "/apps/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

6、修改权限
[root@localhost nginx-1.18.0]# chown -R nginx.nginx /apps/nginx
7、安装后的主要四个目录
[root@localhost nginx-1.18.0]# ll /apps/nginx/
total 0
drwxr-xr-x 2 nginx nginx 333 Sep 24 16:59 conf
drwxr-xr-x 2 nginx nginx  40 Sep 24 16:59 html
drwxr-xr-x 2 nginx nginx   6 Sep 24 16:59 logs
drwxr-xr-x 2 nginx nginx  19 Sep 24 16:59 sbin
[root@localhost nginx-1.18.0]# ll -d /apps/nginx/
drwxr-xr-x 6 nginx nginx 54 Sep 24 16:59 /apps/nginx/

8、连接执行文件
[root@localhost nginx-1.18.0]# ln -s  /apps/nginx/sbin/nginx /usr/sbin/
[root@localhost nginx-1.18.0]# ll /usr/sbin/nginx 
lrwxrwxrwx 1 root root 22 Sep 24 17:07 /usr/sbin/nginx -> /apps/nginx/sbin/nginx

9、查看nginx版本
[root@localhost nginx-1.18.0]# nginx -v
nginx version: nginx/1.18.0
[root@localhost nginx-1.18.0]# nginx  -V
nginx version: nginx/1.18.0
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC) 
built with OpenSSL 1.1.1c FIPS  28 May 2019
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module 
--with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

10、启动和停止nginx
[root@localhost nginx-1.18.0]# nginx
[root@localhost nginx-1.18.0]# ss -ntl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port            
LISTEN      0           128                    0.0.0.0:80                  0.0.0.0:*        
[root@localhost nginx-1.18.0]# nginx -s stop

11、创建nginx自启动文件
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx - high performance web server
After=network.-online.target remote-fs.target nss-lookup.target
wants=network-online.target

[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target

12、创建目录修改配置文件
[root@localhost nginx-1.18.0]# mkdir /apps/nginx/run
[root@localhost nginx-1.18.0]# vim /apps/nginx/conf/nginx.conf
pid        /apps/nginx/run/nginx.pid;

13、验证nginx自启动文件
[root@localhost nginx-1.18.0]# systemctl daemon-reload 
[root@localhost nginx-1.18.0]# ps aux |grep nginx
root       38172  0.0  0.2  12108  1064 pts/0    S+   17:22   0:00 grep --color=auto nginx
[root@localhost nginx-1.18.0]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/system
d/system/nginx.service.[root@localhost nginx-1.18.0]# ps aux |grep nginx
root       38198  0.0  0.1  41048   844 ?        Ss   17:22   0:00 nginx: master process /ap
ps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.confnginx      38199  0.0  1.0  74572  4832 ?        S    17:22   0:00 nginx: worker process
root       38201  0.0  0.2  12108  1048 pts/0    S+   17:22   0:00 grep --color=auto nginx

 

posted @ 2020-09-24 17:29  duanpeng123  阅读(68)  评论(0)    收藏  举报