E
E
Evgeny Ilin2013-03-10 00:51:22
PHP
Evgeny Ilin, 2013-03-10 00:51:22

Nginx as a proxy to a remote host?

Start config:

server {
listen 80;
server_name 127.0.0.1;
access_log /var/log/nginx/transition.access.log;
error_log /var/log/nginx/transition.error.log;
root /var/www/transition;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://node;
proxy_redirect off;
port_in_redirect off;
}
}
upstream node {
server 192.168.21.158:8090;
}

Finite
server {
listen 8090;
server_name ololo.ru
access_log /var/log/nginx/transition.access.log;
error_log /var/log/nginx/transition.error.log;
root /var/www/transition;
location / {
include mime.types;
try_files $uri $uri/ /index.html;
index index.php;
rewrite ^/login/login.php last;
rewrite ^/id /id/index.php last;
rewrite ^/uid/([a-z0-9]+)/([0-9]+)-([0-9]+)-([0-9]+)/?$ /enter.php? uid=$1&inn=$2&kpp=$3&finn=$4 last;
rewrite ^/docview/(.*)$ /docview.php?hash=$1 last;
rewrite ^/(.*)$ /index.php?url=$1&$args last;
}
location ~ \.php$ {
try_files $uri @cakephp;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/transition$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi_params;
}
location ~* \.(js|jpg|jpeg|gif|png|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv |xml|docx|xlsx|txt)$ {
root /var/www/transition;
if ($request_uri ~ "^/ajaxtemp/(.*)$") {
rewrite ^/ajaxtemp/(.*)$ /ajaxtemp/rewriter.php?filename=$1;
}
if ($request_uri ~ "^/admin/(.+)$") {
rewrite ^/admin(.*)$ /admin/app/webroot$1;
break;
}
}
}

If you proxy to the same host , it works. If the value specified in the config is 502.
In access on the remote, it is written:
"GET/HTTP/1.0" 499 0 "
All.
nginx/1.2.1 - on both hosts. Moreover, if you specify ya.ru for the backend, it will proxy.
Night already. Maybe I didn't notice something?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sundukov, 2013-03-10
@alekciy

If you proxy to the same host, it works. If the one specified in the config is 502.

server_name 127.0.0.1;

You don't need to use the IP address as the server name. Names should be used, and not necessarily existing ones. The main thing is that they be in the hosts files on both machines.

A
Alexey Sundukov, 2013-03-10
@alekciy

And the second:

"GET/HTTP/1.0" 499 0 "

clearly indicates the cause of the problem. The start nginx closed the connection without waiting for a response from the end. You just need to raise connection timeouts (such as proxy_send_timeout , proxy_read_timeout and others).
By the way, for debugging it is very useful to use htop and strace (in htop, select the nginx worker process and press S).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question