📜 ⬆️ ⬇️

nginx - frontend configuration to ~ username - public_html

Of course, I understand that it may not be necessary for anyone, since he did not find a proper solution on the Internet. However, earlier, when computers were large, and we were small, so-called home pages were popular. A proud Indian even has a module for this business - userdir.
Recently (June, 2009) I decided to drive the Indian into the backend, and configure nginx with the front end. So I did not find a ready solution for organizing the frontend for nginx. Without thinking twice, I scratched my chin and rolled the following configuration to nginx. Imagine the happiness I experienced when it worked.
So, the task is to force the front end to give the contents from the user's home-wider / home / user / public_html. A request for which in the browser looks like site.name/~user :

  location ~ ^ / ~ ([^ /] *) / (. * \. (bmp | jpg | jpeg | gif | ico | png | css | doc | txt | js | zip | iso | tgz | gz | rar | bz2 | 7z | xls | exe | pdf | ppt | tar | wav | avi | rtf | mp3 | mp4 | mov | mpeg | mpg)) {
     access_log /var/log/nginx/access-frontend.homedir.site.name.log;
     alias / home / $ 1 / public_html / $ 2;
     expires 5d;
     limit_rate 50k;
 }

 location ~ ^ / ~ ([^ /] *) / (. *) {
     access_log /var/log/nginx/access-backend.homedir.site.name.log;
     proxy_set_header Host $ host;
     proxy_set_header X-Real-IP $ remote_addr;
     proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
     proxy_pass http://127.0.0.1:60080;
     proxy_redirect off;
 }

 location ~ * ^. + \. (bmp | jpg | jpeg | gif | ico | png | css | doc | txt | js | zip | iso | tgz | gz | rar | bz2 | 7z | xls | exe | pdf | ppt | tar | wav | avi | rtf | mp3 | mp4 | mov | mpeg | mpg) $ {
     access_log /var/log/nginx/access-frontend.site.name.log;
     expires 5d;
     limit_rate 50k;
     if ($ http_user_agent ~ FDM | Download) {
         limit_rate 50k;
     }
 }

 location = / {rewrite.  /index.php last;  }

 location / {
     access_log /var/log/nginx/access-backend.site.name.log;
     proxy_set_header Host $ host;
     proxy_set_header X-Real-IP $ remote_addr;
     proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
     proxy_pass http://127.0.0.1:60080;
     proxy_redirect off;
 } 

Actually that's all :) Expansions for files processed in the frontend
You can create and add to your own regular expression.
Naturally, we invent the rest of the configuration on our own - this is just a note of the template :)

... the journey continues :)

')

Source: https://habr.com/ru/post/81560/


All Articles