I tried to use yesterday nginx build nuget Mirror server , The mirror server needs two functions :1) Reverse proxy ;2) Content caching .

use nginx Acting as a reverse agent , The configuration is very simple , Just in /etc/nginx/nginx.conf Add one containing proxy_pass Of server Set up :

server {
listen 80;
listen [::]:80;
server_name Image server host name ;
location / {
proxy_pass http://www.nuget.org;
}
}

And add caching , The configuration is a little more complicated .

First, create a folder to hold the cache files , For example, it is used here  /data/nuget-cache .

mkdir /data/nuget-cache

And then in nginx.conf Of http Settings section add proxy_cache_path Set up :

proxy_cache_path /data/nuget-cache levels=1:2 keys_zone=nuget-cache:20m max_size=50g inactive=168h;

* keys_zone Refers to the cache space name .

* max_size Refers to the maximum amount of space a cache file can take up .

* inactive It refers to how long a cache file will not be accessed , It will be deleted .

And then server Settings section add proxy_cache And proxy_cache_valid Set up :

server {
listen 80;
listen [::]:80;
server_name Image server host name ;
location / {
proxy_pass http://www.nuget.org;
proxy_cache nuget-cache;
proxy_cache_valid 168h;

}
}

* proxy_cache What's set up is proxy_cache_path in keys_zone Value .

* proxy_cache_valid Set the cache expiration time , Here, for example. 168 Hours expired .

Set it up and run nginx, Found that only a small part of the content is cached , Most of the content can't be cached , Like the following URL The content of the response cannot be cached :

http://www.myget.org/F/aspnetvnext/api/v2/FindPackagesById%28%29?id=%27System.Linq%27

see http Response head (http headers), Found the following 2 individual http header:

Cache-Control: private
Set-Cookie: ai_session=ad829b6c509946098fa7f8e32fada661|2015-06-24T03:52:38.2032109+00:00|2015-06-24T03:52:38.4219541
+00:00; expires=Wed, 24-Jun-2015 04:22:38 GMT; path=/

The problem is that they cause , Need to be in nginx Pass through proxy_ignore_headers Settings ignore them , The setting method is as follows :

server {
listen 80;
listen [::]:80;
server_name Image server host name ;
location / {
proxy_pass http://www.nuget.org;
proxy_cache nuget-cache;
proxy_cache_valid 168h;
proxy_ignore_headers Set-Cookie Cache-Control;
proxy_hide_header Cache-Control;
proxy_hide_header Set-Cookie;

}
}

【 Reference material 】

Understanding the nginx proxy_cache_path directive

Nginx Caching

【 Related links 】

nuget The solution of domestic image

solve nginx More related articles on the problem that reverse proxy caching doesn't work

  1. nginx Reverse proxy + Cache on +url rewrite + Load balancing ( With health detection ) Deployment records of

    In daily operation and maintenance work , Operation and maintenance personnel will often use nginx Reverse proxy of , Load balancing, caching and other functions to optimize web Service performance . I don't say much nonsense , The following is an introduction to the test environment nginx Reverse proxy + Cache on +url rewrite + Load balancing ( With health detection ) ...

  2. nginx The construction of reverse proxy cache server

    One : Proxy service can be simply divided into forward proxy and reverse proxy : Forward agency : Used to proxy internal network pairs Internet Connection request for ( Such as VPN/NAT), The client specifies the proxy server , And send it directly to the target Web Server's HTTP Request to send first ...

  3. solve nginx Reverse proxy webservice Of soap:address location problem

    original text :https://blog.csdn.net/mn960mn/article/details/50716768 One : Let's start with a web service package com.ws.servic ...

  4. solve Nginx Reverse proxy does not automatically encode special characters Such as gitblit Medium ~ Wavy lines

    The problem is using Nginx When you're doing a reverse proxy , You need to visit the following link http://192.168.14.141/iserver/services/3D-0524hd/rest/realspace/datas/0 ...

  5. nginx Configuration optimization of reverse proxy

    author : Keep every day blog:liuyu.blog.51cto.combbs:bbs.linuxtone.orgmsn:liuyubj520#hotmail.comemail:liuyu105#gmai ...

  6. Nginx Reverse proxy 、 Load balancing 、 Page caching 、URL Rewriting and separation of reading and writing

    Reprint :http://freeloda.blog.51cto.com/2033581/1288553 The outline One . Preface Two . Environmental preparation 3、 ... and . Installation and configuration Nginx Four .Nginx The reverse agent of 5、 ... and .Nginx The burden of ...

  7. Nginx Reverse proxy 、 Load balancing 、 Page caching 、URL Rewriting and separation of reading and writing

    The outline One . Preface Two . Environmental preparation 3、 ... and . Installation and configuration Nginx Four .Nginx The reverse agent of 5、 ... and .Nginx Load balancing 6、 ... and .Nginx Page caching for 7、 ... and .Nginx And URL rewrite 8、 ... and .Nginx The separation of reading and writing notes , operating system ...

  8. Nginx Reverse proxy 、 Load balancing 、 Page caching 、URL Rewriting and read-write separation

    1. Environmental preparation front end Nginx:10.160.65.44 Back end WEB Two servers :10.160.65.49/10.160.65.50 2. install Nginx: download nginx-1.9.15.tar.gz, place ...

  9. Nginx Reverse proxy 、 Load balancing 、 Page caching 、URL rewrite 、 Read write separation and simple dual hot standby

    The outline One . Preface Two . Environmental preparation 3、 ... and . Installation and configuration Nginx  (windows Next nginx install . Configuration and use ) Four .Nginx The reverse agent of 5、 ... and .Nginx Load balancing  ( Load balancing algorithm :nginx Load algorithm up ...

Random recommendation

  1. 【Oracle】oracle And listagg Analysis function

    oracle Analysis function ——listagg piece (1) Use listagg Merge multiple lines of data into one line Example table : select deptno, ename from emp order by deptno, ename ...

  2. Intellij IDEA Common shortcut key ——Mac edition

    http://blog.csdn.net/longshen747/article/details/17204699 http://totohust.iteye.com/blog/1035550 Set from ...

  3. nc Detailed command

    NetCat, There are many in the network tools “ Swiss Army knife ” A reputation as a , Its have Windows and Linux Version of . Because it's short and sharp (1.84 It's just the same version 25k, The old or reduced version is even smaller ). Functional and practical , Designed as a simple . Reliable Internet tools , Accessible ...

  4. tomcat service

    Reference material :http://www.chysoft.net/showinfo.asp?id=84 (1) Tomcat Service installation explain : By default ,tomcat The service for is not installed , Specifically tomcat The safety of service ...

  5. Ubuntu install google Gtest

    (1) Download the source code :http://code.google.com/p/googletest/gtest-1.7.0 (2013)gtest-1.7.0 (2010) (2) README Compilation guide 126 ...

  6. [ Physics and PDEs] The first 1 Chapter one 3 section In a vacuum Maxwell Equations , Lorentz force 3.1 In a vacuum Maxwell Equations

    1. By slightly modifying the previously used local equations, we can get... In vacuum Maxwell Equations : $$\beex \bea \Div {\bf E}&=\cfrac{\rho}{\ve_0},\\ \rot{\bf ...

  7. Mobile webpage making course META How much do you know about labels ?【 turn + Add 】

    One . Tmall <title> Tmall touch screen version </title> <meta content="text/html; charset=utf-8" http-equ ...

  8. Swift in Set( 5、 ... and )Adding & Removing Elements

    Adding Elements internal func _unsafeInsertNew(_ element: __owned Element) { _internalInvariant(coun ...

  9. Metaclass applications ORM Realization

    Let's start with the next simple example # demand import numbers class Field: pass class IntField(Field): # Data descriptor def __init__(self, ...

  10. Ubuntu+Eclipse+SVN Version control configuration notes

    First step : First update the system internal package cache ( Prevent mistakes ) #  sudo dpkg --clear-avail #  sudo apt-get update The second step : install Eclipse Of SVN Interface component “javaH ...