openstack swift as a cache proxy for nginx, swift proxy report 401 error when authenticate

AmyAmy nginx-forum at
Wed Mar 2 03:19:41 UTC 2016

hello, everybody.

I am trying to find a way to use Openstack swift to cache static file for a
web server such as nginx, the below are request step:
1.	 nginx is configured as a load balance proxy server and web server. 
2.	 There are several swift , suppose there are 2, that is swift-A,swift-B
,swift-A is control node,and swift-B is storage node
3.	 client send a request to nginx for url:
4.	 nginx received the request and it is a cache miss, it need to fetch the
content from SWIFT proxy server,
5.	 nginx send a request to swift proxy server for authentication, the url
looks like http://swift-proxy/auth-account, account information is set in
header, the response from swift proxy server contains a auth-token for that
account if authentication success.
6.	 then nginx use this auth-token and put it in a new request header, and
send the new request to the swift proxy server for the original request
content, there could be a map between client request url to the swift proxy
url, for example, /filename.txt --> /account/container/filename.txt, so the
new request url could be
http://swift-proxy/account/container/filename.txt,plus the auth-token.
7.	 swift proxy server response the content to nginx, then nginx cache the
content and pass the response to the client.

I have search for the answer on the internet, and referent this solution:,250458,250463#msg-250463

Then ,I change my nginx configuration like this:

server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
            auth_request /auth/v1.0;
        location /auth/v1.0 {
                proxy_pass_request_body off;
                proxy_set_header Content-Length "";
                proxy_set_header X-Original-URI $request_uri;

Port 80 is for nginx,port 8080 is for swift, both can work independently,
but after I change the configuration ,use chrome browser enter:10.67.
247.21,it just not working like what I expect, swift proxy return 401 error,
swift proxy logs report like this :

Mar  1 20:43:48 localhost journal: proxy-logging
01/Mar/2016/20/43/48 GET /auth/v1.0 HTTP/1.0 401 -
- - 131 - txbfc24355780143568445c4ddf5d774e3 - 0.0003 -
Mar  1 20:43:48 localhost journal: tempauth -
01/Mar/2016/20/43/48 GET /auth/v1.0 HTTP/1.0 401 -
- - - - txbfc24355780143568445c4ddf5d774e3 - 0.0007

I don’t know does it matter if I use a chrome browser to send request to
swift ,it looks like some unrecognized char are include in the request
header .while I use shell command to send request, it works fine, like this

[root at localhost ~]# curl -v -H 'X-Storage-User: service:swift' -H
'X-Storage-Pass:swift '
*   Trying
* Connected to ( port 8080 (#0)
> GET /auth/v1.0 HTTP/1.1
> Host:
> User-Agent: curl/7.47.1
> Accept: */*
> X-Storage-User: service:swift
> X-Storage-Pass:swift 
< HTTP/1.1 200 OK
< X-Storage-Url:
< X-Auth-Token: AUTH_tk4f2eaa45b35c47b4ab0b955710cce6da
< Content-Type: text/html; charset=UTF-8
< X-Storage-Token: AUTH_tk4f2eaa45b35c47b4ab0b955710cce6da
< Content-Length: 0
< X-Trans-Id: tx3b90f2a8a3284f52951cc80ca41f104a
< Date: Tue, 01 Mar 2016 21:10:50 GMT
* Connection #0 to host left intact

Below is my swift proxy-server.conf:


bind_port = 8080
bind_ip =

workers = 1

user = swift

log_facility = LOG_LOCAL1

eventlet_debug = true


pipeline = catch_errors healthcheck proxy-logging cache tempurl ratelimit
tempauth staticweb  proxy-logging proxy-server


use = egg:swift#catch_errors
set log_name = cache_errors


use = egg:swift#healthcheck
set log_name = healthcheck


use = egg:swift#proxy_logging
set log_name = proxy-logging


use = egg:swift#ratelimit
set log_name = ratelimit


use = egg:swift#crossdomain
set log_name = crossdomain


use = egg:swift#tempurl
set log_name = tempurl

use = egg:swift#tempauth
set log_name = tempauth
user_admin_admin = admin .admin .reseller_admin
user_test_tester = testing .admin
user_test2_tester2 = testing2 .admin
user_test_tester3 = testing3
user_service_swift = swift .admin


use = egg:swift#staticweb
set log_name = staticweb


use = egg:swift#memcache
set log_name = memcache


use = egg:swift#proxy
set log_name = proxy
allow_account_management = true

account_autocreate = true

I have no idea for the 401 error occurred and how to solve this question.Are
there some configuration error in my swift or nginx configuration file?

Thanks for your time,

Posted at Nginx Forum:,264991,264991#msg-264991

More information about the nginx mailing list