nginx下载网站 http://nginx.org/ http://nginx.org/en/download.html > http://nginx.org/download/nginx-1.15.8.tar.gz
cd nginx-1.15.8
./configure --sbin-path=/usr/local/nginx/nginx
–conf-path=/usr/local/nginx/nginx.conf
–pid-path=/usr/local/nginx/nginx.pid
–with-http_ssl_module
–with-pcre=/root/pcre-8.37 #pcre指定源程序 是为了开启重写 rewrite
–with-zlib=/usr/local/zlib-1.2.8 #zlib指定编译的路径 是为了开启gzip
–with-openssl=/usr/local/openssl-1.0.2q #openssl也制定编译后的路径
pcre支持包 https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz 之前下载最新版的pere2报错,换成pcre版本后不报错
make[1]: *** [/usr/local/pcre//Makefile] Error 127 --with-pcre//Makefile
指向源程序目录
make[1]: *** [/usr/local/openssl//.openssl/include/openssl/ssl.h] Error 127
修改nginx源程序中auto lib openssl conf 中.openssl使他的路径中不重复openssl名称。
make[1]: *** [objs/src/http/modules/ngx_http_log_module.o] Error 1
修改nginx原目录下objc下的Makefile 去掉-Werror
后编译成功
zlib下载网址http://www.zlib.net/zlib-1.2.11.tar.gz
openssl https://www.openssl.org/source/ https://www.openssl.org/source/openssl-1.0.2q.tar.gz
nginx成功编译后
pcre是源目录
zlib是源目录
openssl是编译后的目录
make && make install 后
需要将nginx的运行程序创建快捷方式到usr/bin 中 ln -s 源文件名称 快捷文件名称
创建启动脚本
注意路径
#!/bin/bash
#nx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginx=/opt/nginx/nginx
nginx_config=/opt/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginx ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginx -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginx
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginx -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
此时的nginx.conf文件并没有开启include
include extra/www.conf;
include /opt/nginx/*.conf
创建一个nginx用户和用户组,将/opt目录下的nginx全部改变所属用户和组
useradd nginx -g nginx -s /sbin/nologin -d /var/webroot/
chown -R nginx nginx/
chgrp -R nginx nginx/