I am using the following configuration
upstream site {
server 127.0.0.1:3000;
keepalive 64;
}
server {
listen 80;
error_page 400 404 500 502 503 504 /50x.html;
location /50x.html {
internal;
root /usr/share/nginx/www;
}
location /static {
root /opt/site/static;
access_log off;
expires max;
}
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://site;
proxy_intercept_errors on;
}
}
I have saved it to /etc/nginx/sites-available/site.conf and symlinked to it /etc/sites-enabled/site.conf , and when I restart nginx it gives me the following error:
Restarting nginx: [emerg]: unknown directive "keepalive" in /etc/nginx/sites-enabled/site.conf:3
There are no keepalive directive. Use keepalive_timeout instead. And you can't put it inside upsream, use inside http, server or location.
Option "keepalive" is provided by keepalive module. And since 1.1.4 keepalive functionality is included in the main code.
Related
I have alfresco 5.2 community edition installed on ubuntu machine with nginx as proxy. updated the SSL recently for my new domain. It is working fine and site is accessible through https://new.domain.com/share/
I want to redirect all http traffic to https://new.domain.com/share/. Tried changing the server config block but getting an error too many redirects .
currently new.domain.com is redirecting to https://new.domain.com/ and need to change it from new.domain.com to https://new.domain.com/share/
nginx.conf
#user nginx;
#worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
#events {
# worker_connections 1024;
#}
events {}
http {
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;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name new.domain.com;
return 301 https://new.domain.com$request_uri;
location / {
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 504 /50x.html;
location = /50x.html {
}
}
}
server {
listen 443 default ssl;
server_name new.domain.com;
access_log on;
ssl on;
ssl_certificate /etc/nginx/ssl/NEW.DOMAIN.COM.crt;
ssl_certificate_key /etc/nginx/ssl/new.domain.com.key;
location / {
client_max_body_size 4000M;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
sub_filter_types text/javascript;
sub_filter_once off;
}
}
}
alfresco.conf
# Set proxy cache path
proxy_cache_path /var/cache/nginx/alfresco levels=1 keys_zone=alfrescocache:256m max_size=512m inactive=1440m;
# Alfresco Repository Tomcat instance
upstream alfresco {
server localhost:8080;
}
# Share Web client Tomcat instance
upstream share {
server localhost:8080;
}
# Default server config. Update server name.
server {
listen 80 ;
listen [::]:80 ;
server_name example.com www.example.com;
root /opt/alfresco/www;
index index.html index.htm;
# Redirect root requests to Share. Do not do this if you use AOS
# rewrite ^/$ /share;
# redirect server error pages to the static page /50x.html
#
error_page 502 503 504 /maintenance.html;
location = /maintenance.html {
root /opt/alfresco/www;
}
# Access to old Alfresco web client. Remove this location if not needed.
location /alfresco {
# Allow for large file uploads
client_max_body_size 4000M;
# Proxy all the requests to Tomcat
proxy_http_version 1.1;
#proxy_buffering off;
proxy_pass http://alfresco;
proxy_set_header Proxy "";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Server $host;
}
location /share {
# Allow for large file uploads
client_max_body_size 4000M;
# Proxy all the requests to Tomcat
proxy_http_version 1.1;
#proxy_buffering off;
proxy_pass http://share;
proxy_set_header Proxy "";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Server $host;
}
location /share/proxy/alfresco {
# This section is for allowing to rewrite 50x response to 401 on Ajax req.
# This forces Share to reload page, and thus display maintenance page
# Allow for large file uploads
client_max_body_size 4000M;
# Proxy all the requests to Tomcat
proxy_http_version 1.1;
#proxy_buffering off;
proxy_pass http://share;
proxy_set_header Proxy "";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Server $host;
proxy_intercept_errors on;
error_page 502 503 504 =401 /maintenance.html;
}
location /share/res/ {
# Proxy all the requests to Tomcat
proxy_http_version 1.1;
proxy_pass http://share;
proxy_set_header Host $http_host;
proxy_set_header Proxy "";
proxy_cache alfrescocache;
proxy_cache_min_uses 1;
proxy_cache_valid 200 302 1440m;
proxy_cache_valid 404 1m;
proxy_cache_use_stale updating error timeout invalid_header http_500 http_502 http_503 http_504;
}
location / {
# Allow for large file uploads
client_max_body_size 4000M;
# Proxy all the requests to Tomcat
proxy_http_version 1.1;
#proxy_buffering off;
proxy_pass http://alfresco;
proxy_set_header Proxy "";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Server $host;
}
location /downtime.js {
# Allow the maintenance page to pick up downtime.js script
root /opt/alfresco/www;
}
}
Redirection code:
server {
if ($host = new.domain.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name new.domain.com;
return 404;
}
I get an 5#5: *23 upstream timed out (110: Connection timed out) while connecting to upstream, client: error with nginx.
I have read and applied the Nginx reverse proxy causing 504 Gateway Timeout question. However my case sligthly different, because I have three endpoint to proxy.
My nginx.conf:
worker_processes 1;
events { worker_connections 1024; }
http {
server {
listen 80;
listen [::]:80;
server_name rollcall;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass "http://[hostip]:8080/api";
}
location /api/attendance {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass "http://[hostip]:8000/api";
}
location / {
include /etc/nginx/mime.types;
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
My "/" and the application with port:8080 proxy as they are expected, however my application with port:8000 does not proxy, and get the above mentioned timeout exception. If I try to request the application with the port:8000, the application works as expected.
What could cause the above described timeout, and how I should change my conf file?
The problem was not a Nginx or Docker related problem. The port 8000 was not opened on the application droplet.
In my use case, I am trying to do a reverse proxy using nginx server. I have two applications running in two ports. For example app server is running port 9090 and api server is running in 8081.
I will be running nginx server in port in 8080. If I get /api request, nginx should redirect to api server. Other requests should go to app server.
I have the following nginx.conf,
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream app {
server 127.0.0.1:9090;
keepalive 64;
}
upstream api {
server 127.0.0.1:8081;
keepalive 64;
}
#
# The default server
#
server {
listen 8080;
server_name howti;
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://api;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
#proxy_set_header Connection "";
#proxy_http_version 1.1;
}
location /{
rewrite /(.*) /$1 break;
proxy_pass http://app;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
#proxy_set_header Connection "";
#proxy_http_version 1.1;
}
# redirect not found pages to the static page /404.html
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
But it is not working. I am not able to debug the request in nginx? Could someone help me with this? Thanks
I'm trying to redirect my particular domain to Tomcat where multipe Application is running, but I'm getting "ERR_TOO_MANY_REDIRECTS" ERROR in the browser
My configuration has below
server {
listen 80;
server_name www.mydomain.com;
location / {
proxy_pass http://localhost:7070/AppName;
proxy_read_timeout 600s;
client_max_body_size 200m;
}
}
Recently I configured my Odoo app to forward all requests via Nginx.
You need to add something like this to your Nginx config:
upstream tomcat {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name www.mydomain.com;
location / {
proxy_pass http://tomcat;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect 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;
proxy_set_header X-Forwarded-Proto https;
}
proxy_read_timeout 600s;
client_max_body_size 200m;
}
}
If this doesn't work, for reference, you may want to check this article: https://www.rosehosting.com/blog/install-odoo-on-a-debian-8-vps-with-nginx-as-a-reverse-proxy/
I hope you'll find this useful.
It is common to set the proxy_redirect directive in the same way as the proxy_pass directive. see for example configure-nginx-with-proxy-pass.
location ~ ^/stash {
proxy_pass http://IP:7990;
proxy_redirect http://IP:7990/ /stash;
}
but I got the ERR_TOO_MANY_REDIRECTS error with this configuration... so i changed it for "proxy_redirect off;" as suggested here, and it solved my problem!
here is the configuration for my gitlab server:
server {
listen 80;
server_name reverseproxy.mydomain.org;
location /gitlab/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host-Real-IP $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://172.xx.xx.xxx:10080;
#proxy_redirect http://172.xx.xx.xxx:10080/ /gitlab/;
proxy_redirect off;
}
}
NB: i also needed to remove the directive "proxy_set_header Host $host;" for my gitlab server, powered by docker-gitlab.
I am having issues getting my nginx + tomcat 7 reverse proxy setup working.
Basically I want https://192.168.10.101 to serve content from the upstream cluster/webapp/; However I am getting a 404 page from my applicaton.
Any hints on whats going wrong would be greatly appreciated.
My configuration is given below.
server {
server_name 192.168.10.101;
access_log /var/log/nginx/mysite-access.log;
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/mysite.crt;
ssl_certificate_key /etc/nginx/ssl/private/mysite_pvt.key;
location / {
proxy_redirect off;
proxy_pass https://tccluster/webapp/;
rewrite_log on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 0;
}
}
upstream tccluster {
server 192.168.56.103:8443;
server 192.168.56.104:8443;
}
Finally figured it out. The app has a filter that redirects to /webapp/index.html , which made nginx make the request for /webapp/webapp/index.html which was giving the 404.
I added a rewrite rule
location / {
proxy_pass https://backend/webapp/;
proxy_redirect 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;
rewrite ^/webapp/(.*)$ /$1 last;
}
And this seems to be working for now !
full nginx config to pass to tomcat context :
server {
listen 80; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
listen [::]:80;
server_name tomcat-context.domain.com ;
# individual nginx logs for this vhost
access_log /var/log/nginx/tomcat-context_domain_access.log main;
error_log /var/log/nginx/tomcat-context_domain_error.log;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location / {
proxy_pass http://127.0.0.1:10080/tomcat-context/;
proxy_redirect 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;
rewrite ^/tomcat-context/(.*)$ /$1 last;
}
location /tomcat-context {
rewrite ^/tomcat-context(.*)$ $1 redirect;
}
}