0
votes

What I´m looking for is setup a reverse proxy with nginx and forward them to another nginx server. The reverse proxy should forward all traffic to the webserver to a related port.

Nginx Reverse Config:

server {
        listen   80; 

        root /var/www/; 
        index index.php index.html index.htm;

        server_name example.com; 

        location / {
        try_files $uri $uri/ /index.php;
        }

        location ~ \.php$ {

        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://192.168.0.10:1478;

         }

         location ~ /\.ht {
                deny all;
        }
}

In this case the reverse should redirect all traffic to the webserver 192.168.0.10:1478

Nginx Webserver Config:

 server {
        listen 1478;

        root /var/www/public_html;
        index index.html index.htm index.php;

        server_name IP-Reverse;
}

This is not working... Is there a config mistake?

In this case I use 2 Servers, 1 Webserver nginx and one reverse nginx. All traffic should forwared from the reverse proxy to the webserver on a specific port. All requests from the reverse proxy to the webserver should be only allowed from the reverse ip

1
What exactly not working? I don't see anything about proceeding php. - Alexey Ten

1 Answers

0
votes

The error code :Bad Request (400), the problem is there is nothing in my log files..

This is my webserver vhost config:

server {

 listen 7894 ;
  server__name srv1.domain.com;

  root /var/www/public_html;

  index index.html index.htm index.php;

   charset utf-8;

   location / {
       try_files $uri $uri/ /index.php?$query_string;
   }

   location = /favicon.ico { access_log off; log_not_found off; }
   location = /robots.txt  { access_log off; log_not_found off; }

   access_log off;
   error_log  /var/log/nginx/error.log error;

   sendfile off;

   client_max_body_size 100m;

   location ~ \.php$ {
       fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_intercept_errors off;

fastcgi_buffer_size 16k;

fastcgi_buffers 4 16k;
   }

   location ~ /\.ht {
   deny all;
   }

and here it is my reverse config:

    server {

    listen 80;

    listen 443 ssl;

    server_name domain.com;

     root /var/www/public_html;

     index index.html index.htm index.php;

    error_log /var/log/nginx/error.log;

     charset utf-8;

       location / {
            try_files $uri $uri/ /index.php;
            }

            location ~ \.php$ {


     proxy_set_header X-Real-IP  $remote_addr;

     proxy_set_header X-Forwarded-For $remote_addr;

     proxy_set_header Host $host;

     proxy_pass http://webserveripaddress:7894;

             }

             location ~ /\.ht {
                    deny all;
            }

    ####SSL####
  ssl_certificate     /etc/ssl/domain.crt;
  ssl_certificate_key /etc/ssl/domain.key;

    }

Hope this helps. Thank you ver much!