Monday, August 21, 2017

Nginx not making proxy_pass when getting files (other than index.html) from Apache's Document Root



I think I'm chasing my own tail here and I've decided to ask all you gurus.



I have two machines, one has a reverse proxy Nginx and the other an Apache running several virtual hosts.



The nginx correctly does the proxy_pass and I'm able to view the index.html, but not any other file than that.



I attach the conf file for the nginx host (nbte.com.br, (192.168.4.30)) and the apache virtual host (SIPREPWWPRESS03.simosa.inet)




NGINX - 083-nbte.conf



server {

listen 80;
server_name nbte.com.br www.nbte.com.br;

access_log /var/log/nginx/nbte.access.log;
error_log /var/log/nginx/nbte.error.log error;


error_page 404 403 /handle404.html;
#error_page 502 503 504 /handle503.html;
error_page 500 502 503 504 /handle500.html;

location = /handle404.html {
root html/errores-prxy;
}

location = /handle503.html {
root html/errores-prxy;

}

location = /handle500.html {
root html/errores-prxy;
}

location = / {
proxy_pass http://SIPREPWWPRESS03.simosa.inet/;
}



SIPREPWWPRESS03.simosa.inet resolves to 192.168.16.79



APACHE - 021-nbte.conf





ServerName nbte.com.br
ServerAlias nbte.com.br www.nbte.com.br


DocumentRoot "/apps/htmlsites/nbte"

ErrorLog "logs/error_nbte.log"
CustomLog "logs/nbte-access.log" combined







Options +Indexes FollowSymLinks
#AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all



# ModSecurity exceptions

SecRuleRemoveById 990011

SecRuleRemoveById 960017
SecRuleRemoveById 960015
SecRuleRemoveById 970013





I've almost no experience with NGINX, I'm very very new to it and specially it's reverse proxy functioning. Nevertheless, I think it's a NGINX issue, since looking at the error log file I find error lines each time a static file is requested:




2015/06/25 12:00:04 [error] 5075#0: *1393 open() "/etc/nginx/html/Informacoes-Financeiras-30-junho-2014-Norte-Brasil-Transmissora-Energia.pdf" failed (2: No such file or directory), client: 192.168.14.1, server: nbte.com.br, request: "GET /Informacoes-Financeiras-30-junho-2014-Norte-Brasil-Transmissora-Energia.pdf HTTP/1.1", host: "nbte.com.br", referrer: "http://nbte.com.br/"


2015/06/25 12:00:04 [error] 5075#0: *1393 open() "/etc/nginx/html/Informacoes-Financeiras-30-junho-2014-Norte-Brasil-Transmissora-Energia.pdf" failed (2: No such file or directory), client: 192.168.14.1, server: nbte.com.br, request: "GET /Informacoes-Financeiras-30-junho-2014-Norte-Brasil-Transmissora-Energia.pdf HTTP/1.1", host: "nbte.com.br", referrer: "http://nbte.com.br/"


The file Informacoes-Financeiras-30-junho-2014-Norte-Brasil-Transmissora-Energia.pdf is located inside Apache's document root /apps/htmlsites/nbte alog with index.html



Many thanks in advance. Any help is really appreciated.


Answer




This



location = / {
proxy_pass http://SIPREPWWPRESS03.simosa.inet/;
}


Should be



location / {

proxy_pass http://SIPREPWWPRESS03.simosa.inet/;
}


As per http://wiki.nginx.org/HttpCoreModule#location




location = / {
# matches the query / only.
[ configuration A ]
}



location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.
[ configuration B ]




Example requests:



/ -> configuration A
/index.html -> configuration B



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...