: This article mainly introduces nginx Reverse proxy (and optimization). If you are interested in the PHP Tutorial, refer to it. Install nginx with source code
Install three nginx dependencies: pcre, openssl, and zlib.
To compile pcre, you need:
yum install gcc gcc-c++ pcre-devel
Download source code package
Official website download the latest version can be: http://www.pcre.org/http://www.openssl.orghttp://www.zlib.net/http://nginx.org
Note: pcre can only be 8.0 +, but not pcre2.
An error is reported:
make[2]: *** No rule to make target `libpcre.la'. Stop.
In addition to the latest stable version I use for pcre, I need to provide a pcre source package:
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
Compile
Here, you do not need to compile and install them separately, and directly go to the decompressed nginx directory for execution.
Assume that all files are stored in the/home directory.
./configure --prefix=/data/nginx --with-http_realip_module \--with-http_sub_module \--with-http_flv_module \--with-http_dav_module \--with-http_gzip_static_module \--with-http_stub_status_module \--with-http_addition_module \--with-pcre=/home/pcre2-10.00 \--with-openssl=/home/openssl-1.0.2a \--with-http_ssl_module \--with-zlib=/home/zlib-1.2.8
Note that the green three are directories of the specified source code, not the installation directory, because this method is co-compiled, and you do not need to compile and install pcre, ssl, zlib in advance.
Then:
makemake install
Run
Install nginx in/data/nginx according to the above installation method
. /Data/nginx/sbin/nginx-c/data/nginx/conf/nginx. conf # because it requires a specified configuration file to run, execution of this configuration file does not return, it is recommended to use script control
The script is as follows:
#!/bin/sh# config: /usr/local/nginx/conf/nginx.confnginx_path="/data/nginx"nginx_pid="/data/nginx/logs/nginx.pid"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit0[ -x $nginx_path/sbin/nginx ] || exit0RETVAL=0prog="nginx"start() {# Start daemons.if [ -e$nginx_pid-a ! -z $nginx_pid ];thenecho"nginx already running...."exit1fiif [ -e$nginx_path/conf/nginx.conf ];thenecho -n $"Starting $prog: "$nginx_path/sbin/nginx -c $nginx_path/conf/nginx.conf & RETVAL=$?[ $RETVAL-eq0 ] && {touch /var/lock/subsys/$progsuccess $"$prog"}echoelseRETVAL=1fireturn$RETVAL}# Stop daemons.stop() { echo -n $"Stopping $prog: " killproc -d10$nigx_path/sbin/nginx RETVAL=$? echo [ $RETVAL = 0 ] && rm -f$nginx_pid /var/lock/subsys/$prog}# See how we were called.case"$1"instart) start ;;stop) stop ;;reconfigure) stop start ;;status) status $prog RETVAL=$? ;;*) echo $"Usage: $0 {start|stop|reconfigure|status}"exit1esacexit$RETVAL
If the script name is nginx. sh
You can:
./nginx.sh status|stop|start....
Proxy configuration