编译安装nginx和模块

一 编译安装nginx

yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel
wget http://nginx.org/download/nginx-1.8.1.tar.gz
ls -l
tar xf nginx-1.8.1.tar.gz 
cd nginx-1.8.1/
[root@iscsi nginx-1.8.1]# useradd www -s /sbin/nologin -M
[root@iscsi nginx-1.8.1]# ./configure --help #查看编译时指定的参数
[root@iscsi nginx-1.8.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module
[root@iscsi nginx-1.8.1]# make && make install

添加nginx模块

[root@iscsi conf]# /usr/local/nginx-1.8.1/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module
增加(--with-file-aio --with-http_realip_module)
[root@iscsi nginx-1.8.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
[root@iscsi nginx-1.8.1]# make ##不要make install,不然就覆盖安装了
[root@iscsi nginx-1.8.1]# ll objs/nginx
-rwxr-xr-x. 1 root root 5308752 Apr 23 02:52 objs/nginx
[root@iscsi nginx-1.8.1]# cp /usr/local/nginx-1.8.1/sbin/nginx /usr/local/nginx-1.8.1/sbin/nginx.20200423
[root@iscsi nginx-1.8.1]# cp objs/nginx /usr/local/nginx-1.8.1/sbin/nginx
cp: overwrite ‘/usr/local/nginx-1.8.1/sbin/nginx’? y
[root@iscsi nginx-1.8.1]# /usr/local/nginx-1.8.1/sbin/nginx -t

添加nginx第三方模块

[root@iscsi 1]# tar xf v0.3.0
[root@iscsi 1]# ll nginx_upstream_check_module-0.3.0/
total 244
-rw-rw-r--. 1 root root      0 Oct  2  2014 CHANGES
-rw-rw-r--. 1 root root   5483 Oct  2  2014 check_1.2.1.patch
-rw-rw-r--. 1 root root   7130 Oct  2  2014 check_1.2.2+.patch
-rw-rw-r--. 1 root root   7094 Oct  2  2014 check_1.2.6+.patch
-rw-rw-r--. 1 root root   6791 Oct  2  2014 check_1.5.12+.patch
-rw-rw-r--. 1 root root   6701 Oct  2  2014 check_1.7.2+.patch
-rw-rw-r--. 1 root root   6943 Oct  2  2014 check.patch
-rw-rw-r--. 1 root root    749 Oct  2  2014 config
drwxrwxr-x. 2 root root     43 Oct  2  2014 doc
-rw-rw-r--. 1 root root   1709 Oct  2  2014 nginx-sticky-module.patch
drwxrwxr-x. 2 root root     29 Oct  2  2014 nginx-tests
-rw-rw-r--. 1 root root  46860 Oct  2  2014 ngx_http_upstream_check_handler.c
-rw-rw-r--. 1 root root   3718 Oct  2  2014 ngx_http_upstream_check_handler.h
-rw-rw-r--. 1 root root 112230 Oct  2  2014 ngx_http_upstream_check_module.c
-rw-rw-r--. 1 root root    529 Oct  2  2014 ngx_http_upstream_check_module.h
-rw-rw-r--. 1 root root   2848 Oct  2  2014 ngx_http_upstream_jvm_route_module.patch
-rw-rw-r--. 1 root root  11384 Oct  2  2014 README
drwxrwxr-x. 6 root root     79 Oct  2  2014 test
-rw-rw-r--. 1 root root   3342 Oct  2  2014 upstream_fair.patch
drwxrwxr-x. 2 root root     81 Oct  2  2014 util
[root@iscsi 1]# cd  nginx-1.8.1/
[root@iscsi nginx-1.8.1]# yum install patch -y
[root@iscsi nginx-1.8.1]# patch -p1 <../nginx_upstream_check_module-0.3.0/check_1.7.2+.patch 
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
Hunk #1 succeeded at 9 with fuzz 2.
Hunk #2 succeeded at 95 (offset 4 lines).
Hunk #3 succeeded at 159 (offset 4 lines).
Hunk #4 succeeded at 227 (offset 4 lines).
Hunk #5 succeeded at 339 (offset 4 lines).
Hunk #6 succeeded at 381 (offset 4 lines).
Hunk #7 succeeded at 443 (offset 4 lines).
Hunk #8 succeeded at 541 (offset -1 lines).
patching file src/http/ngx_http_upstream_round_robin.h
[root@iscsi nginx-1.8.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --add-module=../nginx_upstream_check_module-0.3.0
[root@iscsi nginx-1.8.1]# make
make[1]: Leaving directory `/home/1/nginx-1.8.1'
make -f objs/Makefile manpage
make[1]: Entering directory `/home/1/nginx-1.8.1'
sed -e "s|%%PREFIX%%|/usr/local/nginx-1.8.1|" \
    -e "s|%%PID_PATH%%|/usr/local/nginx-1.8.1/logs/nginx.pid|" \
    -e "s|%%CONF_PATH%%|/usr/local/nginx-1.8.1/conf/nginx.conf|" \
    -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx-1.8.1/logs/error.log|" \
    < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/1/nginx-1.8.1'
[root@iscsi nginx-1.8.1]# cp /usr/local/nginx-1.8.1/sbin/nginx /usr/local/nginx-1.8.1/sbin/nginx.202004231
[root@iscsi nginx-1.8.1]# cp objs/nginx /usr/local/nginx-1.8.1/sbin/nginx
cp: overwrite ‘/usr/local/nginx-1.8.1/sbin/nginx’? y
nginx: the configuration file /usr/local/nginx-1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.8.1/conf/nginx.conf test is successful

一部分配置文件

[root@iscsi conf]# cat nginx.conf
    include /usr/local/nginx/conf/conf.d/*.conf;
    upstream 8080 {
         server ip1:8080 weight=1;
         server ip2:8080 weight=1;
check interval=3000 rise=2 fall=2 timeout=1000 type=http;
    }
    upstream 8040 {
         server ip1:8040 weight=1;
         server ip2:8040 weight=1;
check interval=3000 rise=2 fall=2 timeout=1000 ;
    }

查看启动和访问

[root@iscsi nginx-1.8.1]# /usr/local/nginx-1.8.1/sbin/nginx 
[root@iscsi nginx-1.8.1]# ps -ef|grep nginx
root      43889      1  0 03:07 ?        00:00:00 nginx: master process /usr/local/nginx-1.8.1/sbin/nginx
root      43890  43889  0 03:07 ?        00:00:00 nginx: worker process
root      43891  43889  0 03:07 ?        00:00:00 nginx: worker process
root      43892  43889  0 03:07 ?        00:00:00 nginx: worker process
root      43893  43889  0 03:07 ?        00:00:00 nginx: worker process
root      43895  38595  0 03:07 pts/3    00:00:00 grep --color=auto nginx
[root@iscsi nginx-1.8.1]# lsof -i :8080
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   43889 root    7u  IPv4 105688      0t0  TCP *:webcache (LISTEN)
nginx   43890 root    7u  IPv4 105688      0t0  TCP *:webcache (LISTEN)
nginx   43891 root    7u  IPv4 105688      0t0  TCP *:webcache (LISTEN)
nginx   43892 root    7u  IPv4 105688      0t0  TCP *:webcache (LISTEN)
nginx   43893 root    7u  IPv4 105688      0t0  TCP *:webcache (LISTEN)
[root@iscsi nginx-1.8.1]# firewall-cmd --zone=public --add-port=8080/tcp --permanent 
success
[root@iscsi nginx-1.8.1]# firewall-cmd --reload
success
[root@iscsi nginx-1.8.1]# curl -I ip1
curl: (7) Failed connect to ip1:80; Connection refused
[root@iscsi nginx-1.8.1]# systemctl stop firewalld.service 
[root@iscsi nginx-1.8.1]# curl -I http://ip1:8080/Server/
HTTP/1.1 200 
Server: nginx/1.8.1
Date: Thu, 23 Apr 2020 10:09:27 GMT
Content-Type: text/html;charset=UTF-8
Connection: keep-alive
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 3600
Access-Control-Allow-Headers: Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,userID,userId,Authentication,authentication,content-type

命令帮助

[root@iscsi nginx-1.8.1]# /usr/local/nginx-1.8.1/sbin/nginx -h
nginx version: nginx/1.8.1
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx-1.8.1/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

猜你喜欢

转载自www.cnblogs.com/yhq1314/p/12762689.html