欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nginx-1.13.x源码安装

程序员文章站 2024-01-30 16:26:52
...
Nginx 安装配置

【依赖库】
[ zlib ]
(下载)http://download.chinaunix.net/download.php?id=24013&ResourceID=12241
[ pcre ]
apt-get install libpcre-dev
[ openssl ]
(下载)http://download.chinaunix.net/download.php?id=39379&ResourceID=11

【configure】
[ 编译命令 ]
./configure 
--prefix=/work/nginx/ 
--with-pcre 
--with-http_ssl_module 
--with-openssl=/usr/local/ssl	
#--with-zlib=/usr/local/zlib 	#此处会导致 make distclean 异常


[ 成功提示 ]
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + using OpenSSL library: /usr/local/ssl
  + using zlib library: /usr/local/zlib

  nginx path prefix: "/work/nginx/"
  nginx binary file: "/work/nginx//sbin/nginx"
  nginx modules path: "/work/nginx//modules"
  nginx configuration prefix: "/work/nginx//conf"
  nginx configuration file: "/work/nginx//conf/nginx.conf"
  nginx pid file: "/work/nginx//logs/nginx.pid"
  nginx error log file: "/work/nginx//logs/error.log"
  nginx http access log file: "/work/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"	


【 make 错误 】
[ .openssl 目录问题 ]
/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/usr/local/src/nginx-1.9.9'
make: *** [build] Error 2	

[ 解决方式 ]
修改文件:/usr/local/src/nginx-1.9.9/auto/lib/openssl/conf
找到:
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"	

替换为:
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"	

其实就是去掉 .openssl 目录。

[ make distclean ]
make -f objs/Makefile
make[1]: Entering directory `/home/newton/nginx-1.13.4'
cd /usr/local/zlib \
	&& make distclean \
	&& CFLAGS="-O2 -fomit-frame-pointer -pipe " CC="cc" \
		./configure \
	&& make libz.a
/bin/sh: 3: Syntax error: "&&" unexpected
make[1]: *** [/usr/local/zlib/libz.a] Error 2
make[1]: Leaving directory `/home/newton/nginx-1.13.4'
make: *** [build] Error 2

[ 解决方案 ]
将 configure 的编辑模块中,去掉 --with-zlib
** 如果有其它解决方案,欢迎分享 **

【make & make install】
[ make ]
	objs/src/http/modules/ngx_http_upstream_zone_module.o \
	objs/ngx_modules.o \
	-ldl -lpthread -lcrypt -lpcre /usr/local/openssl/lib/libssl.a /usr/local/openssl/lib/libcrypto.a -ldl -lz \
	-Wl,-E
sed -e "s|%%PREFIX%%|/work/nginx/|" \
		-e "s|%%PID_PATH%%|/work/nginx//logs/nginx.pid|" \
		-e "s|%%CONF_PATH%%|/work/nginx//conf/nginx.conf|" \
		-e "s|%%ERROR_LOG_PATH%%|/work/nginx//logs/error.log|" \
		< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/newton/nginx-1.13.4'	


[ make install ]
make -f objs/Makefile install
make[1]: Entering directory `/home/newton/nginx-1.13.4'
test -d '/work/nginx/' || mkdir -p '/work/nginx/'
test -d '/work/nginx//sbin' \
		|| mkdir -p '/work/nginx//sbin'
test ! -f '/work/nginx//sbin/nginx' \
		|| mv '/work/nginx//sbin/nginx' \
			'/work/nginx//sbin/nginx.old'
cp objs/nginx '/work/nginx//sbin/nginx'
test -d '/work/nginx//conf' \
		|| mkdir -p '/work/nginx//conf'
cp conf/koi-win '/work/nginx//conf'
cp conf/koi-utf '/work/nginx//conf'
cp conf/win-utf '/work/nginx//conf'
test -f '/work/nginx//conf/mime.types' \
		|| cp conf/mime.types '/work/nginx//conf'
cp conf/mime.types '/work/nginx//conf/mime.types.default'
test -f '/work/nginx//conf/fastcgi_params' \
		|| cp conf/fastcgi_params '/work/nginx//conf'
cp conf/fastcgi_params \
		'/work/nginx//conf/fastcgi_params.default'
test -f '/work/nginx//conf/fastcgi.conf' \
		|| cp conf/fastcgi.conf '/work/nginx//conf'
cp conf/fastcgi.conf '/work/nginx//conf/fastcgi.conf.default'
test -f '/work/nginx//conf/uwsgi_params' \
		|| cp conf/uwsgi_params '/work/nginx//conf'
cp conf/uwsgi_params \
		'/work/nginx//conf/uwsgi_params.default'
test -f '/work/nginx//conf/scgi_params' \
		|| cp conf/scgi_params '/work/nginx//conf'
cp conf/scgi_params \
		'/work/nginx//conf/scgi_params.default'
test -f '/work/nginx//conf/nginx.conf' \
		|| cp conf/nginx.conf '/work/nginx//conf/nginx.conf'
cp conf/nginx.conf '/work/nginx//conf/nginx.conf.default'
test -d '/work/nginx//logs' \
		|| mkdir -p '/work/nginx//logs'
test -d '/work/nginx//logs' \
		|| mkdir -p '/work/nginx//logs'
test -d '/work/nginx//html' \
		|| cp -R html '/work/nginx/'
test -d '/work/nginx//logs' \
		|| mkdir -p '/work/nginx//logs'
make[1]: Leaving directory `/home/newton/nginx-1.13.4'

【配置快捷方式】
ln /work/nginx/sbin/nginx /usr/bin/nginx

【启动Nginx】
nginx

【查看进程】
[email protected]:/work/project# ps awx|grep nginx
33665 ? Ss 0:00 nginx: master process nginx
33666 ? S 0:00 nginx: worker process
34029 pts/0 S+ 0:00 grep --color=auto nginx

【Nginx配置】
主要是:日志、端口号、脚本目录、首页文件名;
打开配置文件: /work/nginx/conf/nginx.conf
#[ 错误日志 ]
error_log  logs/error.log;
#[ 服务相关 ]
server {
        listen       88;				#监听HTTP端口;
        server_name  localhost;		#访问地址;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /work {			#脚本根目录
            root   html;				#入口目录
            index  index.html index.htm;	#默认执行的首页文件
        }


【重启Nginx】
nginx -s reload :修改配置后重新加载生效