首先上官网下载源码包,我下载版本是:nginx-1.13.12.tar.gzhtml
而后在/usr/local/src/ 下解压:nginx
而后三步走:web
第一步:ui
./configure --prefix=/opt/server/nginx/ --user=nginx --group=nginx --with-this
http_ssl_module --with-http_stub_status_module server
注意:这里须要with什么模块,主要就看咱本身的须要,我目前暂时须要htm
--with-http_ssl_module ip
--with-http_stub_status_modulessl
这两个模块,而后开始后面两步:ci
第二步:
make
第三步:
make install
安装成功后,看到在/opt/server/nginx 目录下已经成功了:
[root@jordy nginx]# pwd
/opt/server/nginx
[root@jordy nginx]# ll
total 16
drwxr-xr-x 2 root root 4096 May 18 17:15 conf
drwxr-xr-x 2 root root 4096 May 18 17:15 html
drwxr-xr-x 2 root root 4096 May 18 17:15 logs
drwxr-xr-x 2 root root 4096 May 18 17:15 sbin
ok,下面咱们能够启动nginx:
/opt/server/nginx/sbin/nginx
启动成功后查看下服务:
[root@jordy nginx]# ps -ef |grep nginx | grep -v grep
root 8947 1 0 17:23 ? 00:00:00 nginx: master process /opt/server/nginx/sbin/nginx
nginx 8948 8947 0 17:23 ? 00:00:00 nginx: worker process
恩,ok了。
而后在server里面配置上本身的域名:
server {
listen 80;
server_name xxx.xxxx.com;
……
成功后,从新加载nginx ,则执行:
/opt/server/nginx/sbin/nginx -s reload
成功后访问咱们的index.html页,看到:
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
ok,这样就安装完毕,下面讲讲升级的问题;
假如咱们的web服务运行了一段时间,因业务发展须要,须要支持http2,这个时候咱们须要用到--with-http_v2_module模块;或者说咱们须要用到更高版本的nginx,那怎么办呢?很简单,只须要从新按新的需求编译一份便可,而后把旧的那份./sbin/nginx 替换就ok,而且nginx支持upgrade,具体流程见下面:
首先进入源码目录:
cd /usr/local/src/nginx/nginx-1.13.12
而后按新的须要的参数从新编译一份,注意仍是在/opt/server/nginx目录下:
./configure --prefix=/opt/server/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module
而后 make不须要make insall
而后移走旧的./sbin/nginx
mv /opt/server/nginx/sbin/nginx /opt/server/nginx/sbin/nginx.old
而后拷贝当前目录下cp ./objs/nginx /opt/server/nginx/sbin/nginx来替换旧的
[root@jordy nginx_http_v2]# pwd
/opt/server/nginx_http_v2
[root@jordy nginx_http_v2]# ll
total 16
drwxr-xr-x 2 root root 4096 May 18 17:36 conf
drwxr-xr-x 2 root root 4096 May 18 17:36 html
drwxr-xr-x 2 root root 4096 May 18 17:36 logs
drwxr-xr-x 2 root root 4096 May 18 17:36 sbin
而后 运行 make upgrade
[root@jordy nginx-1.13.12]# make upgrade
/opt/server/nginx/sbin/nginx -t
nginx: the configuration file /opt/server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/server/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /opt/server/nginx/logs/nginx.pid`
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
make: *** [upgrade] Error
而后查看下升级后的版本以及编译参数:
[root@jordy sbin]# ./nginx -V
nginx version: tang/810
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/server/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module
而后就能够正常使用了;