Showing posts with label reverse-proxy. Show all posts
Showing posts with label reverse-proxy. Show all posts

Sunday, May 20, 2018

http configuration to connect different type of backened app server from single virtual host

Leave a Comment

I have a apache http server that acts as proxy to connect to backened app servers.

e.g. MachineA(https) -> MachineB(http:reverseproxy) -> MachineCn(http:App)

Here MachineA(Public_lb) port 9002 is mapped with MachineB(internal apache) port 7777.

In backened, I have different application servers running

for e.g.

  1. MachineC1 -> Weblogic
  2. MachineC2 -> Tomcat
  3. MachineC3 -> NodeJS
  4. MachineC4 -> Flask

Here there is single servername(MachineA: public_facing_lb) and port(9002). Here is my existing configuration in MachineB(apache reverseproxy server)looks like which works fine now for all weblogic connections. But when I add the proxy for other apps, it never works properly.

What I am doing wrong here ?

LoadModule weblogic_module   "/u01/oracle/ohssa/ohs/modules/mod_wl_ohs.so"  RewriteEngine On     RewriteCond %{HTTPS} on     RewriteRule ^$ http://%{HTTP_HOST} [L,R]        <IfModule mod_weblogic.c>        NameVirtualHost *:7777       <VirtualHost *:7777>         ServerName https://public_facing_lb:9002         RewriteEngine       On         RewriteOptions inherit         RewriteRule ^/$ /pod/reactaphome [PT]         Debug ALL         MatchExpression /         DebugConfigInfo ON         WLLogFile /var/log/httpd/wlproxy-qa.log         KeepAliveEnabled ON         KeepAliveSecs  15         WLProxySSLPassThrough ON         ProxyPreserveHost On        <Location /pod/reactapp1>        ProxyPass  http://nodejssrv1:1337        ProxyPassReverse  http://nodejssrv1:1337      </Location>       <Location /pod/flaskapp1>        ProxyPass  http://flasksrv1:8080        ProxyPassReverse  http://flasksrv1:8080      </Location>       <Location /pod/tomcatapp1>        ProxyPass  http://tomcatsrv1:8080        ProxyPassReverse  http://tomcatsrv1:8080      </Location>       <Location /pod/console>         SetHandler weblogic-handler         WebLogicHost wlssrv1         WeblogicPort 7001         WLSRequest On         ProxyPass  http://wlssrv1:7001/console         ProxyPassReverse http://wlssrv1:7001/console      </Location>         SetHandler weblogic-handler         WebLogicHost wlssrv1         WeblogicPort 7001         ProxyPass /pod/wlsapp1 http://wlssrv1:7001/wlsapp1         ProxyPassReverse /pod/wlsapp1 http://wlssrv1:7001/wlsapp1         ProxyPass /pod/wlsapp2 http://wlssrv1:7001/wlsapp2         ProxyPassReverse /pod/wlsapp2 http://wlssrv1:7001/wlsapp2         ProxyPass /pod/wlsapp3 http://wlssrv1:7001/wlsapp3         ProxyPassReverse /pod/wlsapp3 http://wlssrv1:7001/wlsapp3          ProxyPass /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList         ProxyPassReverse /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList         ProxyPass /wlsapphome http://wlssrv1:7001/resources/getAppsList         ProxyPassReverse /wlsapphome http://wlssrv1:7001/resources/getAppsList       </VirtualHost>     </IfModule>  

I might be doing mistake in putting the other app config inside the weblogic if module. If I am creating multiple virtual hosts, at any point of time only the first virtualhost works.

Do I need to load modules for tomcat, nodejs and flask to communicate, as the pages get loaded broken. Like mod_wl_ohs used for weblogic ?

1 Answers

Answers 1

I don't know why your ifmodule statement is applied to the whole VirtualHost, why not limit it to only to the rules for weblogic reverse proxy?

Also you didn't close your Location statements, checkout this modified file:

LoadModule weblogic_module   "/u01/oracle/ohssa/ohs/modules/mod_wl_ohs.so" RewriteEngine On RewriteCond %{HTTPS} on RewriteRule ^$ http://%{HTTP_HOST} [L,R]  <VirtualHost *:7777>     ServerName https://public_facing_lb:9002     RewriteEngine       On     RewriteOptions inherit     RewriteRule ^/$ /pod/reactaphome [PT]     Debug ALL     MatchExpression /     DebugConfigInfo ON     WLLogFile /var/log/httpd/wlproxy-qa.log     KeepAliveEnabled ON     KeepAliveSecs  15     WLProxySSLPassThrough ON     ProxyPreserveHost On     <Location /pod/reactaphome>      ProxyPass  http://admiring_agnesi:8080      ProxyPassReverse  http://admiring_agnesi:8080    </Location>     <Location /pod/tomcatapp>      ProxyPass  http://admiring_agnesi:1337      ProxyPassReverse  http://admiring_agnesi:1337    </Location>     <IfModule mod_weblogic.c>     <Location /pod/console>       SetHandler weblogic-handler       WebLogicHost wlssrv1       WeblogicPort 7001       WLSRequest On       ProxyPass  http://wlssrv1:7001/console       ProxyPassReverse http://wlssrv1:7001/console    </Location>      SetHandler weblogic-handler     WebLogicHost wlssrv1     WeblogicPort 7001     ProxyPass /pod/wlsapp1 http://wlssrv1:7001/wlsapp1     ProxyPassReverse /pod/wlsapp1 http://wlssrv1:7001/wlsapp1     ProxyPass /pod/wlsapp2 http://wlssrv1:7001/wlsapp2     ProxyPassReverse /pod/wlsapp2 http://wlssrv1:7001/wlsapp2     ProxyPass /pod/wlsapp3 http://wlssrv1:7001/wlsapp3     ProxyPassReverse /pod/wlsapp3 http://wlssrv1:7001/wlsapp3      ProxyPass /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList     ProxyPassReverse /wlsapphome/global http://wlssrv1:7001/resources/getGlobalAppsList     ProxyPass /wlsapphome http://wlssrv1:7001/resources/getAppsList     ProxyPassReverse /wlsapphome http://wlssrv1:7001/resources/getAppsList    </IfModule>   </VirtualHost> 

Could you try with that? All the requests to the *:7777 port will be handled.

Read More

Wednesday, March 7, 2018

Serve content from external server via apache

Leave a Comment

I am running my web app at abc.com with apache as the web server.

I have some static pages hosted on SquareSpace... eg. abc.squarespace.com/landing

I want to configure apache to serve content from abc.squarespace.com when it get's a request for abc.com/landing

I've done this in nginx by using proxy_pass with the backend as abc.squarespace.com for location /landing. But I'm not sure how to do this in Apache. No luck doing research on the web as well.

Thanks in advance.

1 Answers

Answers 1

Message body cannot contain URLs with abc.com, so I will be using example.com and example.squarespace.com.

I believe you are looking for frame forwarding. In order to implement it, use the following steps:

  1. On example.squarespace.com allow frame forwarding from example.com by setting the appropriate HTTP headers via web server configuration:

X-Frame-Options: ALLOW-FROM https://example.com/

For detailed explanation refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

  1. Verify that Apache mod_proxy_http is enabled at example.com:

# apachectl -M | grep proxy_http proxy_http_module (shared)

  1. Set the following rewrite rules in Apache configuration or .htaccess file to serve content from http://example.squarespace.com/landing

<IfModule proxy_http_module> RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC] RewriteRule ^landing(.*) http://example.squarespace.com/landing [P] </IfModule>

The syntax here is the same as for Apache mod_rewrite.

Read More

Monday, February 5, 2018

How to configure https support in 443 for apache AND node?

Leave a Comment

Actual state:

http://www.example.com/mypage apache http: OK!
https://www.example.com/mypage apache https: OK!

http://www.example.com:8000 node http: OK!
https://www.example.com:8000 node https: Not working (still)

I've tried to modify node program to be

var express = require('express'); var app = express(); var https = require('https'); var fs = require('fs');  var server = http.createServer(app);  https.createServer({          key: fs.readFileSync("/etc/letsencrypt/live/www.example.com/privkey.pem"),         cert: fs.readFileSync("/etc/letsencrypt/live/www.example.com/fullchain.pem"),         ca: fs.readFileSync("/etc/letsencrypt/live/www.example.com/chain.pem") }, app).listen(443); 

The obvious problem here is that apache is ALREADY listenning to port 443, then

Error: listen EADDRINUSE :::443 

Is there a way to use Apache 443 to serve SSL for node?

2 Answers

Answers 1

You can only bind one process to a given port on your server.

That said, the correct way to do this is to have Apache listen on 443, then use mod_proxy to forward the traffic to nodejs either on an HTTP port (not w/ SSL, but you're only talking across localhost) or on a unix socket.

A good example of how to do that with port 80/HTTP is here: http://blog.podrezo.com/making-node-js-work-with-apache/

<VirtualHost *:80>   ServerName pastebin.mydomain.com   ServerAlias www.pastebin.mydomain.com   DocumentRoot /var/www/pastebinjs/   Options -Indexes   ErrorDocument 503 /maintenance.html    ProxyRequests on   ProxyPass /maintenance.html !   ProxyPass / http://localhost:8000/ </VirtualHost> 

But the theory is the same if you add the Proxy* lines to your existing HTTPS endpoint.

Answers 2

Your node HTTPS server can run on any port - let's say 9090 instead of the 443 you have set. Use Apache to redirect any traffic that comes in https://example.com to your node https server listening on 9090.

Check out apache reverse-proxy for more information on how to set this up :)

Read More

Sunday, February 4, 2018

HTTP status code names are missing when using Nginx

Leave a Comment

I'm using Nginx to

redirect all HTTP requests to HTTPS

in my spring boot application.This is the nginx configuration that i'm using,with that i was able to redirect all requests to Https but when i do it i get the status code returned correctly but it doesnt have the status code name anymore.if i remove nginx and run spring boot application alone i can get the http status with its code name and code.

server {    listen 80 default_server;   listen [::]:80 default_server;   server_name _ ;    access_log /var/log/nginx/access.log;   error_log /var/log/nginx/error.log;    proxy_set_header X-Forwarded-Proto $scheme;   proxy_set_header X-Real-IP $remote_addr;   proxy_set_header Host $host;   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;     if ( $http_x_forwarded_proto != 'https' ) {     return 307 https://$host$request_uri;   }    location / {     proxy_set_header X-Forwarded-Proto http;     proxy_pass http://localhost:7070;       expires -1;   }  } 

what am i doing wrong in here should i use proxy_redirect instead of proxy_pass, or am i missing anything in here.that'd be great if you can help.

1 Answers

Answers 1

In the same config file

listen on 80 to redirect req to https (443)

server {     listen 80;     listen [::]:80;     server_name your_url.com www.your_url.com;      return 301 https://your_url.com$request_uri; } 

listen on 433

server {     listen 443 ssl default_server;     listen [::]:443 ssl default_server;      location / {             # proxy pass to your app              proxy_pass http://localhost:7070;             proxy_http_version 1.1;             proxy_set_header Upgrade $http_upgrade;             proxy_set_header Connection 'upgrade';             proxy_set_header Host $host;             proxy_cache_bypass $http_upgrade;     } 

This is the way I do it, and works perfectly for me, cheers!

Read More

Thursday, November 30, 2017

Caching reverse proxy for dynamic content

Leave a Comment

I was thinking about asking on Software Recommendations, but then I've found out that it may be a too strange request and it needs some clarification first.

My points are:

  • Each response contains an etag
    • which is a hash of the content
    • and which is globally unique (with sufficient probability)
  • The content is (mostly) dynamic and may change anytime (expires and max-age headers are useless here).
  • The content is partly user-dependent, as given by the permissions (which itself change sometimes).

Basically, the proxy should contain a cache mapping the etag to the response content. The etag gets obtained from the server and in the most common case, the server does not deal with the response content at all.

It should go like follows: The proxy always sends a request to the server and then either

  • 1 the server returns only the etag and the proxy makes a lookup based on it and
    • 1.1 on cache hit,
      • it reads the response data from cache
      • and sends a response to the client
    • 1.2 on cache miss,
      • it asks the server again and then
      • the server returns the response with content and etag,
      • the proxy stores it in its cache
      • and sends a response to the client
  • 2 or the server returns the response with content and etag,
    • the proxy stores the data in its cache
    • and sends a response to the client

For simplicity, I left out the handling of the if-none-match header, which is rather obvious.

My reason for this is that the most common case 1.1 can be implemented very efficiently in the server (using its cache mapping requests to etags; the content isn't cached in the server), so that most requests can be handled without the server dealing with the response content. This should be better than first getting the content from a side cache and then serving it.

In case 1.2, there are two requests to the server, which sounds bad, but is no worse than the server asking a side cache and getting a miss.

Q1: I wonder, how to map the first request to HTTP. In case 1, it's like a HEAD request. In case 2, it's like GET. The decision between the two is up to the server: If it can serve the etag without computing the content, then it's case 1, otherwise, it's case 2.

Q2: Is there a reverse proxy doing something like this? I've read about nginx, HAProxy and Varnish and it doesn't seem to be the case. This leads me to Q3: Is this a bad idea? Why?

Q4: If not, then which existing proxy is easiest to adapt?

An Example

A GET request like /catalog/123/item/456 from user U1 was served with some content C1 and etag: 777777. The proxy stored C1 under the key 777777.

Now the same request comes from user U2. The proxy forwards it, the server returns just etag: 777777 and the proxy is lucky, finds C1 in its cache (case 1.1) and sends it to U2. In this example, neither the clients not the proxy knew the expected result.

The interesting part is how could the server know the etag without computing the answer. For example, it can have a rule stating that requests of this form return the same result for all users, assuming that the given user is allowed to see it. So when the request from U1 came, it computed C1 and stored the etag under the key /catalog/123/item/456. When the same request came from U2, it just verified that U2 is permitted to see the result.

1 Answers

Answers 1

Q1: It is a GET request. The server can answer with an "304 not modified" without body.

Q2: openresty (nginx with some additional modules) can do it, but you will need to implement some logic yourself (see more detailed description below).

Q3: This sounds like a reasonable idea given the information in your question. Just some food for thought:

  • You could also split the page in user-specific and generic parts which can be cached independently.

  • You shouldn't expect the cache to keep the calculated responses forever. So, if the server returns a 304 not modified with etag: 777777 (as per your example), but the cache doesn't know about it, you should have an option to force re-building the answer, e.g. with another request with a custom header X-Force-Recalculate: true.

  • Not exactly part of your question, but: Make sure to set a proper Vary header to prevent caching issues.

  • If this is only about permissions, you could maybe also work with permission infos in a signed cookie. The cache could derive the permission from the cookie without asking the server, and the cookie is tamper proof due to the signature.

Q4: I would use openresty for this, specifically the lua-resty-redis module. Put the cached content into a redis key-value-store with the etag as key. You'd need to code the lookup logic in Lua, but it shouldn't be more than a couple of lines.

Read More

Saturday, October 14, 2017

Nginx, load-balancing using sticky and least connections algorithms simulteniously

Leave a Comment

We use Nginx as load-balancer for our websocket application. Every backend server keeps session information so every request from client must be forwarded on the same server. So we use ip_hash directive to achieve this:

upstream app {     ip_hash;     server 1; } 

The problem appears when we want to add another backend server:

upstream app {     ip_hash;     server 1;     server 2; } 

New connections go to server 1 and server 2 - but this is not what we need in this situation as load on server 1 continues to increase - we still need sticky sessions but least_conn algorithm enabled too - so our two servers receive approximately equal load.

We also considered using Nginx-sticky-module but the documentaton says that if no sticky cookie available it will fall back to round-robin default Nginx algorithm - so it also does not solve a problem.

So the question is can we combine sticky and least connections logic using Nginx? Do you know which other load balancers solve this problem?

2 Answers

Answers 1

Probably using the split_clients module could help

upstream app {     ip_hash;     server 127.0.0.1:8001; }  upstream app_new {     ip_hash;     server 127.0.0.1:8002; }  split_clients "${remote_addr}AAA" $upstream_app {     50% app_new;     *   app; } 

This will split your traffic and create the variable $upstreap_app the one you could use like:

server {    location /some/path/ {    proxy_pass http://$upstream_app; } 

This is a workaround to the least_conn and the load balancer that work with sticky sessions, the "downside" is that if more servers need to be added, a new stream needs to be created, for example:

split_clients "${remote_addr}AAA" $upstream_app {     30% app_another_server;     30% app_new;     *   app; } 

For testing:

for x in {1..10}; do \   curl "0:8080?token=$(LC_ALL=C; cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"; done 

More info about this module could be found in this article (Performing A/B testing)

Answers 2

You can easily achieve this using HAProxy and I indeed suggest going through it thoroughly to see how your current setup can benefit.

With HA Proxy, you'd have something like:

backend nodes     # Other options above omitted for brevity     cookie SRV_ID prefix     server web01 127.0.0.1:9000 cookie check     server web02 127.0.0.1:9001 cookie check     server web03 127.0.0.1:9002 cookie check 

Which simply means that the proxy is tracking requests to-and-fro the servers by using a cookie.

However, if you don't want to use HAProxy, I'd suggest you setup you change your session implementation to use an in-memory DB such as redis/memcached. This way, you can use leastconn or any other algorithm without worrying about sessions.

Read More

Thursday, March 23, 2017

Proxy with express.js

Leave a Comment

To avoid same-domain AJAX issues, I want my node.js web server to forward all requests from URL /api/BLABLA to another server, for example other_domain.com:3000/BLABLA, and return to user the same thing that this remote server returned, transparently.

All other URLs (beside /api/*) are to be served directly, no proxying.

How do I achieve this with node.js + express.js? Can you give a simple code example?

(both the web server and the remote 3000 server are under my control, both running node.js with express.js)


So far I found this https://github.com/nodejitsu/node-http-proxy/ , but reading the documentation there didn't make me any wiser. I ended up with

var proxy = new httpProxy.RoutingProxy(); app.all("/api/*", function(req, res) {     console.log("old request url " + req.url)     req.url = '/' + req.url.split('/').slice(2).join('/'); // remove the '/api' part     console.log("new request url " + req.url)     proxy.proxyRequest(req, res, {         host: "other_domain.com",         port: 3000     }); }); 

but nothing is returned to the original web server (or to the end user), so no luck.

9 Answers

Answers 1

You want to use http.request to create a similar request to the remote API and return its response.

Something like this:

var http = require('http');  /* your app config here */  app.post('/api/BLABLA', function(req, res) {    var options = {     // host to forward to     host:   'www.google.com',     // port to forward to     port:   80,     // path to forward to     path:   '/api/BLABLA',     // request method     method: 'POST',     // headers to send     headers: req.headers   };    var creq = http.request(options, function(cres) {      // set encoding     cres.setEncoding('utf8');      // wait for data     cres.on('data', function(chunk){       res.write(chunk);     });      cres.on('close', function(){       // closed, let's end client request as well        res.writeHead(cres.statusCode);       res.end();     });      cres.on('end', function(){       // finished, let's finish client request as well        res.writeHead(cres.statusCode);       res.end();     });    }).on('error', function(e) {     // we got an error, return 500 error to client and log error     console.log(e.message);     res.writeHead(500);     res.end();   });    creq.end();  }); 

Notice: I haven't really tried the above, so it might contain parse errors hopefully this will give you a hint as to how to get it to work.

Answers 2

I did something similar but I used request instead:

var request = require('request'); app.get('/', function(req,res) {   //modify the url in any way you want   var newurl = 'http://google.com/';   request(newurl).pipe(res); }); 

I hope this helps, took me a while to realize that I could do this :)

Answers 3

To extend trigoman's answer (full credits to him) to work with POST (could also make work with PUT etc):

app.use('/api', function(req, res) {   var url = 'YOUR_API_BASE_URL'+ req.url;   var r = null;   if(req.method === 'POST') {      r = request.post({uri: url, json: req.body});   } else {      r = request(url);   }    req.pipe(r).pipe(res); }); 

Answers 4

I found a shorter and very straightforward solution which works seamlessly, and with authentication as well, using express-http-proxy:

var proxy = require('express-http-proxy');  // New hostname+path as specified by question: var apiProxy = proxy('other_domain.com:3000/BLABLA', {     forwardPath: function (req, res) {         return require('url').parse(req.baseUrl).path;     } }); 

And then simply:

app.use("/api/*", apiProxy); 

I know I'm late to join this party, but I hope this helps someone.

Answers 5

I used the following setup to direct everything on /rest to my backend server (on port 8080), and all other requests to the frontend server (a webpack server on port 3001). It supports all HTTP-methods, doesn't lose any request meta-info and supports websockets (which I need for hot reloading)

var express  = require('express'); var app      = express(); var httpProxy = require('http-proxy'); var apiProxy = httpProxy.createProxyServer(); var backend = 'http://localhost:8080',     frontend = 'http://localhost:3001';  app.all("/rest/*", function(req, res) {   apiProxy.web(req, res, {target: backend}); });  app.all("/*", function(req, res) {     apiProxy.web(req, res, {target: frontend}); });  var server = require('http').createServer(app); server.on('upgrade', function (req, socket, head) {   apiProxy.ws(req, socket, head, {target: frontend}); }); server.listen(3000); 

Answers 6

Ok, here's a ready-to-copy-paste answer using the require('request') npm module and an environment variable *instead of an hardcoded proxy):

coffeescript

app.use (req, res, next) ->                                                    r = false   method = req.method.toLowerCase().replace(/delete/, 'del')   switch method     when 'get', 'post', 'del', 'put'       r = request[method](         uri: process.env.PROXY_URL + req.url         json: req.body)     else       return res.send('invalid method')   req.pipe(r).pipe res 

javascript:

app.use(function(req, res, next) {   var method, r;   method = req.method.toLowerCase().replace(/delete/,"del");   switch (method) {     case "get":     case "post":     case "del":     case "put":       r = request[method]({         uri: process.env.PROXY_URL + req.url,         json: req.body       });       break;     default:       return res.send("invalid method");   }   return req.pipe(r).pipe(res); }); 

Answers 7

I've created a extremely simple module that does exactly this: https://github.com/koppelaar/auth-proxy

Answers 8

First install express and http-proxy-middleware

npm install express http-proxy-middleware --save 

Then in your server.js

const express = require('express'); const proxy = require('http-proxy-middleware');  const app = express(); app.use(express.static('client'));  // Add middleware for http proxying  const apiProxy = proxy('/api', { target: 'http://localhost:8080' }); app.use('/api', apiProxy);  // Render your site const renderIndex = (req, res) => {   res.sendFile(path.resolve(__dirname, 'client/index.html')); } app.get('/*', renderIndex);  app.listen(3000, () => {   console.log('Listening on: http://localhost:3000'); }); 

In this example we serve the site on port 3000, but when a request end with /api we redirect it to localhost:8080.

http://localhost:3000/api/login redirect to http://localhost:8080/api/login

Answers 9

I found a shorter solution that does exactly what I want https://github.com/nodejitsu/node-http-proxy/

After installing http-proxy

npm install http-proxy --save 

Use it like below in your server/index/app.js

var proxyServer = require('http-route-proxy'); app.use('/api/BLABLA/', proxyServer.connect({   to: 'other_domain.com:3000/BLABLA',   https: true,   route: ['/'] })); 

I really have spent days looking everywhere to avoid this issue, tried plenty of solutions and none of them worked but this one.

Hope it is going to help someone else too :)

Read More

Wednesday, March 8, 2017

Nginx Reverse proxy config

Leave a Comment

I'm having issues with getting a simple config to work with nginx. I have a server that host docker containers so nginx is in a container. So lets call the url foo.com. I would like for the url foo.com/service1 to actually just go to foo.com on another port, so it would actually be pulling foo.com:4321 and foo.com/service2 to be pulling foo.com:5432 and so on. Here is the config I have been having issues with.

http {     server {         listen 0.0.0.0:80;          location /service1/ {             proxy_pass http://192.168.0.2:4321/;         }          location /service2/ {             proxy_pass http://192.168.0.2:5432/;         }      } } 

So the services and nginx live at 192.168.0.2. What is the prefered way to be able to do this? Thank you in advance!

As A side note, this is running in a docker container. Thanks!

4 Answers

Answers 1

http {     server {         listen 80;         server_name foo.com;          location /service1/ {             proxy_pass http://192.168.0.2:4321/;         }          location /service2/ {             proxy_pass http://192.168.0.2:5432/;         }      } } 

Answers 2

I have a guess your problem is not related to Nginx per se, but instead it is related to Docker networking. You provided insufficient information to make a detailed conclusion, but here it is a couple of suggestions:

  1. run a simple Docker container at the same host where nginx container is running and try curl from inside that container (I've seen your answer that you are able to call curl from the server running Nginx, but it's not really the same)

  2. for example, if the server running nginx container is OSX or Windows, it may use an intermediate Linux virtual machine with its own network stack, IP addreses, routing, etc.

Answers 3

This is my conf sending to inner glassfish. Check out the use of proxy_redirect off & proxy_set_header X-NginX-Proxy true;

    #Glassfish     location /MyService/   {              index index.html;              add_header Access-Control-Allow-Origin $http_origin;              proxy_set_header X-Real-IP $remote_addr;             proxy_set_header X-NginX-Proxy true;             proxy_ssl_session_reuse off;             proxy_set_header Host $http_host;             proxy_redirect off;             proxy_set_header X-Forwarded-Server $host;             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;             proxy_pass http://127.0.0.1:18000/MyService/;      } 

Answers 4

I think you should check whether your foo.com is pointing to the right ip address or not first by removing the reverse proxy config. E.g.

http {     server {         listen 80;         server_name foo.com;          location / {         }     } } 

Then, if your ip address already has a service running on port 80 you should specify the server_name for each service like in my example. Nginx can only distinguish which service to respond to which domain by server_name.

*My guess is that you forgot the server_name option.

Read More

Sunday, February 26, 2017

Authentication/access control module for reverse proxy NGINX

Leave a Comment

I am looking for a module which does the authentication/access control for reverse proxy (preferable nginx). This module should do:

1. user authentication using credential stored in database (such as postgres) 2. Monitoring the ongoing connection and take action if certain access credential is met. For example, time is expired 3. open source (allow customization) and nginx, ruby(rails) preferable.  

It seems that OpenResty with nginx can do the job. Here is an article talking about access control with Lua on nginx. Here is an example (nginx and Lua) giving me impression that a snippet of file could executed for access (access_by_lua_file):

server {     listen 8080;      location / {       auth_basic           "Protected Elasticsearch";       auth_basic_user_file passwords;        access_by_lua_file '../authorize.lua';  #<<<=====        proxy_pass http://elasticsearch;       proxy_redirect off;     }    } 

I am new to access control with reverse proxy. Any thought is appreciated.

1 Answers

Answers 1

Here is an interesting article on nginx website which answers the question above. https://www.nginx.com/blog/nginx-plus-authenticate-users/

Read More

Friday, April 29, 2016

What's a good customizable web (reverse) proxy in Python with support for WebSockets?

1 comment

I'm looking to implement a simple reverse proxy in Python in which I can specify some custom logic in a request handler, and proxy the request to another URL based on the original request URL, user role (from cookie) etc. I also might want to inject some HTML to the returned page. It must handle WebSockets.

Something similar to this, but in Python: https://github.com/nodejitsu/node-http-proxy#setup-a-stand-alone-proxy-server-with-custom-server-logic

4 Answers

Answers 1

If you do not need to inspect or modify the websocket connections (i.e. you just want them to go through), mitmproxy should cover your use-case pretty well. At the very least, it has a simple script interface you can use to perform your modifications: http://docs.mitmproxy.org/en/latest/scripting/inlinescripts.html

You can enable WebSocket pass-through as specified in this answer.

(Obligatory Disclaimer: I'm one of the mitmproxy authors)

Answers 2

I'm not aware of a completely purpose built thing out there that does exactly this but it shouldn't be to hard to do with asyncio. This of course is assuming you're using Python 3, but if that's the case then http://aiohttp.readthedocs.org/en/stable/ should allow you to fake it. I wouldn't use that for large scale proxying without some serious testing, but for local development stuff it should be fine. Just going to take a bit programming to build that particular tool is all.

Answers 3

Check proxy.py if that fits into your requirements. Doesn't need anything other than the standard python library.

Answers 4

I've used and love tornado http://www.tornadoweb.org/en/stable/ for creating custom webserver/websocket servers in python. That said, if this needs to scale then it would be best of throwing tornado instances behind nginx and allow nginx to take care of the connection handling. Due to the way python (and nodejs too, actually) are single threaded (the infamous GIL) you're best off running one instance per core (maybe 1.5 or 2 per core, depends on the specific applications i/o and cpu usage patterns, in the perfect world 1 per core... only bench-marking will tell) and have nginx act as the reverse proxy.

Read More

Thursday, April 14, 2016

Easy reverse proxy for serving images over ssl

Leave a Comment
This summary is not available. Please click here to view the post.
Read More