Difference between revisions of "Nginx Reverse Proxy"

From vpsget wiki
Jump to: navigation, search
Line 66: Line 66:
 
  server {
 
  server {
 
     listen      191.101.20.10:80;
 
     listen      191.101.20.10:80;
     server_name  www.cnfstudio.com;
+
     server_name  www.domain.com;
 
  #
 
  #
     access_log  /var/log/nginx/www.cnfstudio.access.log  main;
+
     access_log  /var/log/nginx/www.domain.access.log  main;
     error_log  /var/log/nginx/www.cnfstudio.error.log;
+
     error_log  /var/log/nginx/www.domain.error.log;
 
     root  /usr/share/nginx/html;
 
     root  /usr/share/nginx/html;
 
     index  index.html index.htm;
 
     index  index.html index.htm;

Revision as of 13:32, 15 April 2015

Nginx reverse proxy for apache

Scenario 1: nginx installed on separate from apache server.

Apache server ip = 191.101.21.130 Nginx server ip = 191.101.20.10 We assuming that apache listen on default port 80. for more secure you can change it.

/etc/nginx/nginx.conf:

 # For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
user              nginx;
worker_processes  4; 
#
error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;
#
pid        /var/run/nginx.pid; 
#
#
events {
    worker_connections  1024;
}
#
worker_rlimit_nofile 4096;
#
#
http {
    include       /etc/nginx/mime.types;
   default_type  application/octet-stream;
#
   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';
#
   access_log  /var/log/nginx/access.log  main;
#
   sendfile        on;
   #tcp_nopush     on;
#
   #keepalive_timeout  0;
   keepalive_timeout  65;
#
   #gzip  on;
#
   # Load config files from the /etc/nginx/conf.d directory
   # The default server is in conf.d/default.conf
   include /etc/nginx/conf.d/*.conf;
#
}


/etc/nginx/conf.d/default.conf Config:

#
# The default server
#
upstream apachephp  {
      server 191.101.21.130:80; #Apache1
}
# 
#
server {
    listen       191.101.20.10:80;
   server_name  www.domain.com;
#
   access_log  /var/log/nginx/www.domain.access.log  main;
   error_log  /var/log/nginx/www.domain.error.log;
   root   /usr/share/nginx/html;
   index  index.html index.htm;
#
   ## send request back to apache1 ##
   location / {
    proxy_pass  http://apachephp;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}


remember to restart and set to start automatically on boot nginx :

chkconfig nginx on
service nginx start