nginx reverse proxy, ssl offloading, caching and pagespeed all in one.

305
  1. yes it is absolutely possible to combine these nginx servers into one. Just use proxy_pass.
  2. See proxy set header in http block
  3. Double NGINX machines (same config) in combination with DNS round robin (or put something like an AWS load balancer in front, don't know if you have something like it on Azure)
  4. At least. You should think in 1000's of connections with NGINX. Your IIS would probably be the bottleneck. (I don't take into account the extra load Pagespeed processing will put on this setup, you'll have to give it a try and find out)

First in your http block put:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    upstream pagespeed {
          server 127.0.0.1:8081;    # weight=10 max_fails=3 fail_timeout=30s;
    }
    upstream iis {
          server 192.168.0.100:80;    weight=10 max_fails=3 fail_timeout=10s;
          server 192.168.0.101:80;    weight=10 max_fails=3 fail_timeout=10s;
    }

Then you will only need the following server blocks (stripped down)

    server {
    listen       443; #SSL offloader
    server_name  example.com;

         #do some ssl things here

    location / {
    proxy_pass   http://pagespeed; #proxy to pagespeed on same nginx    
    }
}
   server {
        listen       8081;
        server_name  example.com;

         #do some pagespeed things here
         #pagespeed on
    location / {
    proxy_pass   http://iis; # proxy to 2 backend IIS servers
    }
}

Use unix socket in your upstream config for even better performance. Also you can put the pagespeed cache in Memcached.

Share:
305

Related videos on Youtube

Svalorzen
Author by

Svalorzen

Updated on September 18, 2022

Comments

  • Svalorzen
    Svalorzen almost 2 years

    I'm trying to integrate a Python library into Unity3D. Unfortunately, I cannot use IronPython as I have to use a .pyd which is a result of a compilation of a C++ library using Boost Python.

    Thus, I simply wanted to keep a process running with a Python interpreter inside, and I would just synchronously call functions in the interpreter and read the output. I need the interpreter to stay alive as it will need to keep state over time.

    What I am trying to do does not work unfortunately, and I'm not sure what I am missing.

        var process = new System.Diagnostics.Process();
        process.StartInfo.FileName = "python";
        process.StartInfo.Arguments = "-i";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.RedirectStandardOutput = true;
    
        process.Start();
    
        var input = process.StandardInput;
        var error = process.StandardError;
        var output = process.StandardOutput;
    
        string line;
    
        // This would ideally "purge" the initial output from Python, 
        // even though for some reason it is terminating the process.
        Debug.Log("first output:");
        while ((line = output.ReadLine()) != null)
            Debug.Log(line);
        Debug.Log("first error");
        while ((line = error.ReadLine()) != null)
            Debug.Log(line);
    
        // Here I try to pass some commands to the Python interpreter.
        // Even if I remove the outputs from before, I only get
        // "invalid syntax errors" from Python.
        Debug.Log("Passing input");
        input.WriteLine("print('test')");
    
        // Try to read the 'test' output from Python.
        Debug.Log(output.ReadLine());
    
        // Exit the interpreter
        input.WriteLine("exit()");
    
        process.WaitForExit();
        process.Close();
    

    I think there's multiple errors in here, from the way I'm trying to "flush" the output of the Python process from the way I'm trying to pass the input, but I'm not sure what to do differently.

    EDIT: I think "flushing" the input by sending a couple of empty lines to Python fixes my input problems.

    On the other hand, it seems getting output synchronously from a running Process is impossible, as there is no non-blocking way to check if there is more output to read. Even Peek seems to hang. I'm still looking into it..

    • Christopher Perrin
      Christopher Perrin almost 11 years
      So in short you want one Nginx server that terminates the ssl connection, optimzes and caches static assets, and is a reverse proxy for the backend servers.
    • Frank
      Frank almost 11 years
      Correct! An all in one NginX front end to application servers. I am guessing the answer to this question would be useful to anyone running IIS / Apache or even something like Tomcat. I dont know if I am asking is too much. I really only have an asp dev background and configuring linux servers or NginX is very new to me. I really appreciate any comment or guidance!
    • Christopher Perrin
      Christopher Perrin almost 11 years
      ngx_pagespeed has an integrated file and memory cache and must be configured with such.
    • Frank
      Frank almost 11 years
      How can it be used with Downstream servers for serving content from a proxy setup? I am trying to find a sample configuration and the google documentation is limited.
  • Joost van der Laan
    Joost van der Laan almost 11 years
    By the way, don't forget SPDY config in your SSL offloader, another win in performance, easy to accomplish with NGINX.