首先说一下,nginx如果想加第三方模块只能通过源码安装的方式
- 下载nginx源码 下载地址
wget http://nginx.org/download/nginx-1.14.2.tar.gz
- 解压
tar -xzf nginx-1.14.2.tar.gz
可以看到如下目录
-rw-r--r-- 1 1001 1001 288742 Dec 4 22:52 CHANGES
-rw-r--r-- 1 1001 1001 440121 Dec 4 22:52 CHANGES.ru
-rw-r--r-- 1 1001 1001 1397 Dec 4 22:52 LICENSE
-rw-r--r-- 1 1001 1001 49 Dec 4 22:52 README
drwxr-xr-x 6 1001 1001 4096 Mar 2 13:10 auto
drwxr-xr-x 2 1001 1001 4096 Mar 2 13:10 conf
-rwxr-xr-x 1 1001 1001 2502 Dec 4 22:52 configure
drwxr-xr-x 4 1001 1001 4096 Mar 2 13:10 contrib
drwxr-xr-x 2 1001 1001 4096 Mar 2 13:10 html
drwxr-xr-x 2 1001 1001 4096 Mar 2 13:10 man
drwxr-xr-x 9 1001 1001 4096 Mar 2 13:10 src
下面简单解释一下各个目录
- auto
drwxr-xr-x 2 1001 1001 4096 Mar 2 13:10 cc
-rw-r--r-- 1 1001 1001 141 Dec 4 22:52 define
-rw-r--r-- 1 1001 1001 889 Dec 4 22:52 endianness
-rw-r--r-- 1 1001 1001 2812 Dec 4 22:52 feature
-rw-r--r-- 1 1001 1001 136 Dec 4 22:52 have
-rw-r--r-- 1 1001 1001 137 Dec 4 22:52 have_headers
-rw-r--r-- 1 1001 1001 411 Dec 4 22:52 headers
-rw-r--r-- 1 1001 1001 1020 Dec 4 22:52 include
-rw-r--r-- 1 1001 1001 745 Dec 4 22:52 init
-rw-r--r-- 1 1001 1001 4836 Dec 4 22:52 install
drwxr-xr-x 11 1001 1001 4096 Mar 2 13:10 lib //cc和lib库是用来编译的
-rw-r--r-- 1 1001 1001 18253 Dec 4 22:52 make
-rw-r--r-- 1 1001 1001 3183 Dec 4 22:52 module
-rw-r--r-- 1 1001 1001 37857 Dec 4 22:52 modules
-rw-r--r-- 1 1001 1001 136 Dec 4 22:52 nohave
-rw-r--r-- 1 1001 1001 24767 Dec 4 22:52 options
drwxr-xr-x 2 1001 1001 4096 Mar 2 13:10 os //用来判别当前系统信息的
-rw-r--r-- 1 1001 1001 8654 Dec 4 22:52 sources
-rw-r--r-- 1 1001 1001 120 Dec 4 22:52 stubs
-rw-r--r-- 1 1001 1001 2014 Dec 4 22:52 summary
-rw-r--r-- 1 1001 1001 394 Dec 4 22:52 threads
drwxr-xr-x 2 1001 1001 4096 Mar 2 13:10 types
-rw-r--r-- 1 1001 1001 26859 Dec 4 22:52 unix
这个文件夹下的文件都是用来辅助 configure 命令来判断当前系统信息,比如版本、可以提供哪些模块供给nginx使用
2、CHANGE
nginx每一个版本中提供了哪些feature和修复了哪些bug
Changes with nginx 1.14.2 04 Dec 2018
*) Bugfix: nginx could not be built by gcc 8.1.
*) Bugfix: nginx could not be built on Fedora 28 Linux.
*) Bugfix: in handling of client addresses when using unix domain listen
sockets to work with datagrams on Linux.
*) Change: the logging level of the "http request", "https proxy
request", "unsupported protocol", "version too low", "no suitable key
share", and "no suitable signature algorithm" SSL errors has been
lowered from "crit" to "info".
*) Bugfix: when using OpenSSL 1.1.0 or newer it was not possible to
switch off "ssl_prefer_server_ciphers" in a virtual server if it was
switched on in the default server.
*) Bugfix: nginx could not be built with LibreSSL 2.8.0.
*) Bugfix: if nginx was built with OpenSSL 1.1.0 and used with OpenSSL
1.1.1, the TLS 1.3 protocol was always enabled.
*) Bugfix: sending a disk-buffered request body to a gRPC backend might
fail.
*) Bugfix: connections with some gRPC backends might not be cached when
using the "keepalive" directive.
*) Bugfix: a segmentation fault might occur in a worker process if the
ngx_http_mp4_module was used on 32-bit platforms.
3、CHANGE.ru
因为作者是俄罗斯人,所以这个是CHANGE的俄语版本
4、conf
nginx的配置文件,当安装完成后会自动拷贝一份到指定的目录
5、contrib
-rw-r--r-- 1 1001 1001 543 Dec 4 22:52 README
-rw-r--r-- 1 1001 1001 1272 Dec 4 22:52 geo2nginx.pl
drwxr-xr-x 2 1001 1001 4096 Mar 2 13:10 unicode2nginx
drwxr-xr-x 6 1001 1001 4096 Dec 4 22:52 vim
提供nginx语法高亮显示,当我们本地vim不支持nginx语法时将此文件夹拷贝到我们本地
6、html
提供的两个nginx默认页面,欢迎页和50*错误
7、man
nginx的帮助文件
8、src
nginx 的源代码文件
- 配置,生成中间可执行文件
./configure --prefix=/www/server //目录自己定义
编译完成后会生成一个objs文件夹,下边我们看一下里面内容
-rw-r--r-- 1 root root 39521 Mar 2 14:21 Makefile
-rw-r--r-- 1 root root 17763 Mar 2 14:21 autoconf.err
-rw-r--r-- 1 root root 6806 Mar 2 14:21 ngx_auto_config.h
-rw-r--r-- 1 root root 657 Mar 2 14:21 ngx_auto_headers.h
-rw-r--r-- 1 root root 5725 Mar 2 14:21 ngx_modules.c
drwxr-xr-x 9 root root 4096 Mar 2 14:20 src
其中ngx_modules.c是我们的nginx将会安装哪些模块
#include <ngx_config.h>
#include <ngx_core.h>
extern ngx_module_t ngx_core_module;
extern ngx_module_t ngx_errlog_module;
extern ngx_module_t ngx_conf_module;
extern ngx_module_t ngx_regex_module;
extern ngx_module_t ngx_events_module;
extern ngx_module_t ngx_event_core_module;
extern ngx_module_t ngx_epoll_module;
extern ngx_module_t ngx_http_module;
extern ngx_module_t ngx_http_core_module;
extern ngx_module_t ngx_http_log_module;
extern ngx_module_t ngx_http_upstream_module;
extern ngx_module_t ngx_http_static_module;
extern ngx_module_t ngx_http_autoindex_module;
extern ngx_module_t ngx_http_index_module;
extern ngx_module_t ngx_http_mirror_module;
extern ngx_module_t ngx_http_try_files_module;
extern ngx_module_t ngx_http_auth_basic_module;
extern ngx_module_t ngx_http_access_module;
extern ngx_module_t ngx_http_limit_conn_module;
extern ngx_module_t ngx_http_limit_req_module;
extern ngx_module_t ngx_http_geo_module;
extern ngx_module_t ngx_http_map_module;
extern ngx_module_t ngx_http_split_clients_module;
extern ngx_module_t ngx_http_referer_module;
extern ngx_module_t ngx_http_rewrite_module;
extern ngx_module_t ngx_http_proxy_module;
extern ngx_module_t ngx_http_fastcgi_module;
extern ngx_module_t ngx_http_uwsgi_module;
extern ngx_module_t ngx_http_scgi_module;
extern ngx_module_t ngx_http_memcached_module;
extern ngx_module_t ngx_http_empty_gif_module;
extern ngx_module_t ngx_http_browser_module;
extern ngx_module_t ngx_http_upstream_hash_module;
extern ngx_module_t ngx_http_upstream_ip_hash_module;
extern ngx_module_t ngx_http_upstream_least_conn_module;
extern ngx_module_t ngx_http_upstream_keepalive_module;
extern ngx_module_t ngx_http_upstream_zone_module;
extern ngx_module_t ngx_http_write_filter_module;
extern ngx_module_t ngx_http_header_filter_module;
extern ngx_module_t ngx_http_chunked_filter_module;
extern ngx_module_t ngx_http_range_header_filter_module;
extern ngx_module_t ngx_http_gzip_filter_module;
extern ngx_module_t ngx_http_postpone_filter_module;
extern ngx_module_t ngx_http_ssi_filter_module;
extern ngx_module_t ngx_http_charset_filter_module;
extern ngx_module_t ngx_http_userid_filter_module;
extern ngx_module_t ngx_http_headers_filter_module;
extern ngx_module_t ngx_http_copy_filter_module;
extern ngx_module_t ngx_http_range_body_filter_module;
extern ngx_module_t ngx_http_not_modified_filter_module;
ngx_module_t *ngx_modules[] = {
&ngx_core_module,
&ngx_errlog_module,
&ngx_conf_module,
&ngx_regex_module,
&ngx_events_module,
&ngx_event_core_module,
&ngx_epoll_module,
&ngx_http_module,
&ngx_http_core_module,
&ngx_http_log_module,
&ngx_http_upstream_module,
&ngx_http_static_module,
&ngx_http_autoindex_module,
&ngx_http_index_module,
&ngx_http_mirror_module,
&ngx_http_try_files_module,
&ngx_http_auth_basic_module,
&ngx_http_access_module,
&ngx_http_limit_conn_module,
&ngx_http_limit_req_module,
&ngx_http_geo_module,
&ngx_http_map_module,
&ngx_http_split_clients_module,
&ngx_http_referer_module,
&ngx_http_rewrite_module,
&ngx_http_proxy_module,
&ngx_http_fastcgi_module,
&ngx_http_uwsgi_module,
&ngx_http_scgi_module,
&ngx_http_memcached_module,
&ngx_http_empty_gif_module,
&ngx_http_browser_module,
&ngx_http_upstream_hash_module,
&ngx_http_upstream_ip_hash_module,
&ngx_http_upstream_least_conn_module,
&ngx_http_upstream_keepalive_module,
&ngx_http_upstream_zone_module,
&ngx_http_write_filter_module,
&ngx_http_header_filter_module,
&ngx_http_chunked_filter_module,
&ngx_http_range_header_filter_module,
&ngx_http_gzip_filter_module,
&ngx_http_postpone_filter_module,
&ngx_http_ssi_filter_module,
&ngx_http_charset_filter_module,
&ngx_http_userid_filter_module,
&ngx_http_headers_filter_module,
&ngx_http_copy_filter_module,
&ngx_http_range_body_filter_module,
&ngx_http_not_modified_filter_module,
NULL
};
char *ngx_module_names[] = {
"ngx_core_module",
"ngx_errlog_module",
"ngx_conf_module",
"ngx_regex_module",
"ngx_events_module",
"ngx_event_core_module",
"ngx_epoll_module",
"ngx_http_module",
"ngx_http_core_module",
"ngx_http_log_module",
"ngx_http_upstream_module",
"ngx_http_static_module",
"ngx_http_autoindex_module",
"ngx_http_index_module",
"ngx_http_mirror_module",
"ngx_http_try_files_module",
"ngx_http_auth_basic_module",
"ngx_http_access_module",
"ngx_http_limit_conn_module",
"ngx_http_limit_req_module",
"ngx_http_geo_module",
"ngx_http_map_module",
"ngx_http_split_clients_module",
"ngx_http_referer_module",
"ngx_http_rewrite_module",
"ngx_http_proxy_module",
"ngx_http_fastcgi_module",
"ngx_http_uwsgi_module",
"ngx_http_scgi_module",
"ngx_http_memcached_module",
"ngx_http_empty_gif_module",
"ngx_http_browser_module",
"ngx_http_upstream_hash_module",
"ngx_http_upstream_ip_hash_module",
"ngx_http_upstream_least_conn_module",
"ngx_http_upstream_keepalive_module",
"ngx_http_upstream_zone_module",
"ngx_http_write_filter_module",
"ngx_http_header_filter_module",
"ngx_http_chunked_filter_module",
"ngx_http_range_header_filter_module",
"ngx_http_gzip_filter_module",
"ngx_http_postpone_filter_module",
"ngx_http_ssi_filter_module",
"ngx_http_charset_filter_module",
"ngx_http_userid_filter_module",
"ngx_http_headers_filter_module",
"ngx_http_copy_filter_module",
"ngx_http_range_body_filter_module",
"ngx_http_not_modified_filter_module",
NULL
};
- 编译
make
执行后会在objs目录下生成 nginx可执行文件,如果是要做nginx升级的话,千万不要执行接下里的make install 只需要将新生成的nginx文件替换原来的即可
-rw-r--r-- 1 root root 39521 Mar 2 14:21 Makefile
-rw-r--r-- 1 root root 17763 Mar 2 14:21 autoconf.err
-rwxr-xr-x 1 root root 3746432 Mar 2 14:29 nginx
-rw-r--r-- 1 root root 5345 Mar 2 14:29 nginx.8
-rw-r--r-- 1 root root 6806 Mar 2 14:21 ngx_auto_config.h
-rw-r--r-- 1 root root 657 Mar 2 14:21 ngx_auto_headers.h
-rw-r--r-- 1 root root 5725 Mar 2 14:21 ngx_modules.c
-rw-r--r-- 1 root root 31872 Mar 2 14:29 ngx_modules.o
drwxr-xr-x 9 root root 4096 Mar 2 14:20 src
- 安装
make install
大功告成
- 另附上一个nginx启动脚本
# description: nginx http server.
NGINX_SBIN="/www/server/nginx/sbin/nginx"
NGINX_CONF="/www/server/nginx/conf/nginx.conf"
NGINX_PID="/www/server/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL