Welcome! Log In Create A New Profile

Advanced

redirect / proxy_pass with nginx

Posted by fourty2 
redirect / proxy_pass with nginx
November 19, 2015 01:08PM
hi forum,

i'm pretty new to nginx and trying to realize some redirects / proxy passes with it.
the goal is to redirect to different jettys running on different ports on the same server based on the URI. also i need to differ between certificates based on the domain which is used.

the first redirect (/rewrite/here/) and the differentiation between the differend domains works well. but i'm running into trouble for the second pass (/some/location).

the jetty behind the first rewrite is accessible on https://localhost:9443/rewrite/here/ . but the second one is listening directly on https://localhost:8443. so i need to pass https://domain/some/location to https://localhost:8443. it works basically but i end up in a loop while trying to login into the service on the second jetty.

i already tried different settings for the second redirect section but never got it working properly.

thanks in advance!

(nginx.conf attached)
Attachments:
open | download - nginx.conf (2.9 KB)
Re: redirect / proxy_pass with nginx
November 19, 2015 01:11PM
ok, since i'm not able to open the attachment here's the config:

#user nobody;
worker_processes 5;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

# redirect all http requests to https
server {
listen <IP>:80;
server_name _;
rewrite ^ https://$host$request_uri? permanent;
}

# doamin1
server {
listen <IP>:443 ssl spdy;
server_name blahblah.domain1;
ssl_certificate <doamin1>.crt;
ssl_certificate_key <doamin1>.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5:!DSS:!RC4;
ssl_prefer_server_ciphers on;

# rewrite1
rewrite ^/$ /rewrite/here/ redirect;
location /rewrite/here/ {
proxy_http_version 1.1;
proxy_pass https://localhost:9443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# web socket forwarding
proxy_read_timeout 24h;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off;
proxy_buffer_size 4k;
proxy_buffers 100 128k;
proxy_max_temp_file_size 0;
}

# pass2
location /some/location/ {
proxy_pass https://localhost:8443/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# web socket forwarding
proxy_read_timeout 24h;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off;
proxy_buffer_size 4k;
proxy_buffers 100 128k;
proxy_max_temp_file_size 0;
}
}

# domain2
server {
listen <IP>:443 ssl spdy;
server_name blahblah.domain2;
ssl_certificate <doamin2>.crt;
ssl_certificate_key <doamin2>.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5:!DSS:!RC4;
ssl_prefer_server_ciphers on;

# rewrite1
rewrite ^/$ /rewrite/here/ redirect;
location /rewrite/here/ {
proxy_http_version 1.1;
proxy_pass https://localhost:9443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# web socket forwarding
proxy_read_timeout 24h;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off;
proxy_buffer_size 4k;
proxy_buffers 100 128k;
proxy_max_temp_file_size 0;
}

# pass2
location /some/location/ {
proxy_pass https://localhost:8443/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# web socket forwarding
proxy_read_timeout 24h;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off;
proxy_buffer_size 4k;
proxy_buffers 100 128k;
proxy_max_temp_file_size 0;
}

}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 257
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready