As an example, I'd like to serve example.com/public/anyUserName , where anyUserName is a any combination of characters apart from path separators, from the /webapps/client directory. So, a query to example.com/public/Alice and a query to example.com/public/Bob will be served from the same directory. I should be able to request files such as example.com/public/Alice/css/bootstrap.css or http://example.com/public/Alice/client.js without issue. Basically, I want to drop the username part of the url and serve from the same directory but I need to maintain the username in the browser's url.
I've tried many different config tweaks from a regex in the location to this monstrosity but I in every case I get a 404, a 500 which the logs say is a rewrite or internal redirection cycle, a 200 on every resource but each one is the index, or a 200 on every resource but each except the index is a 404.
location /public { index collmanagerclient.html; alias /webapps/client; autoindex on; try_files $2/$3/$4/$5/$6 $2/$3/$4/$5/$6/ =404; } This is my nginx configuration:
server { listen 80; server_name secure.example.me; rewrite ^(.*) https://$server_name$1 permanent; } server { listen 443; server_name secure.example.me; ssl on; ssl_certificate /etc/nginx/ssl/ssl-unified.crt; ssl_certificate_key /etc/nginx/ssl/ssl.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK; ssl_prefer_server_ciphers on; ssl_ecdh_curve secp521r1; root /webapps/client; index collmanagerclient.html; location = / { try_files $uri $uri/ =404; } location ~ /public/(?:[^/]+)/(?<filename>.+) { alias /webapps/client; rewrite ^ $filename last; } location /signup { index collmanagersignup.html; alias /webapps/signup; try_files $uri $uri/ =404; } location /api { #turn gzip off to avoid breaking the cpu gzip off; proxy_pass http://localhost:7801; proxy_buffering off; include /etc/nginx/proxy.conf; } }
Thanks, I've been driven insane over the last little while by this.