Nginx configuration reverse proxy server

  
 

nginx is a high performance web server and it is also a strong reverse proxy server. We just need to download the source code to compile and install the configuration.

First, install Nginx1, install the required PCRE library:

cd /tmpwget -c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre /pcre-8.13.tar.gztar -zxvf pcre-8.13.tar.gzcd pcre-8.13./configure --prefix=/usrmakemake install

2, download nginx source installation:

cd /tmpwget -c http://nginx.org/download/nginx-1.0.8.tar.gztar -zxvf nginx-1.0.8.tar.gzcd nginx-1.0.8./configure --user=nginx --group =nginx --prefix=/usr/local/nginx --with-http_addition_module --with-http_perl_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with -http_sub_module --with-http_dav_modulemakemake install

3, create nginx user:

useradd nginx -s /sbin/nologin -M

4, the following is displayed after installation Some installation paths: nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx configuration prefix: "/usr/local/nginx/conf"nginx Configuration fil e: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/Logs/error.log"nginx http access log file: "/usr/local/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"

Second, configure nginx1, edit configuration file /usr/local/nginx/Conf/nginx.conf

vim /usr/local/nginx/conf/nginx.conf

2, modify the following to remove the # before the first line, to:

user nginx nginx;

Change worker_processes to 2,

worker_processes 2;

Remove # before the following two lines:

error_log logs/error.logpid logs/nginx.pid

Binding the domain name or IP used instead:

listen 80;server_name tied Domain name or IP;

3, configure the reverse proxy content, and replace the URL with HttpSubModule: find location /{root html; index index.html index.htm; add after:

Sub_filter The domain name or IP to be reversed by the proxy's URL; #换URLsub_filter_once off; #Search replace all lines proxy_pass http://reverse proxy URL; proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Accept-Encoding ""; #清编码

3, write nginx startup script, set boot self-start:

vim /etc/init.d/nginx

Startup script content see here

chmod 755 /etc/init.d/nginxchkconfig --level 345 nginx on

4, test reverse proxy browser input reverse proxy Domain name or IP, view can open normally, URL is replaced.

Copyright © Windows knowledge All Rights Reserved