{"id":458,"date":"2014-10-18T22:10:03","date_gmt":"2014-10-18T20:10:03","guid":{"rendered":"http:\/\/www.hauweele.net\/~gawen\/blog\/?p=458"},"modified":"2014-10-18T22:31:14","modified_gmt":"2014-10-18T20:31:14","slug":"nginx-home-directories-and-php","status":"publish","type":"post","link":"https:\/\/hauweele.net\/~gawen\/blog\/?p=458","title":{"rendered":"Nginx home directories and PHP"},"content":{"rendered":"<p>I use nginx as my main HTTP server. \u00a0I want the users to be able to publish their own pages in a special directory (public_html) within their home directory. They should also be able to use PHP\u00a0scripts if they want to. You can access the user webpage (that is the content of their <em>public_html<\/em> directory) with this URL: <em>http:\/\/[server]\/~[user]\/<\/em>. Here is a snippet of the configuration I use to do so:<\/p>\n<pre>index index.html index.xml index.php;\r\n\r\n# PHP in home directory\r\nlocation ~ ^\/~(.+?)(\/.*\\.php)(.*)$ {\r\n  alias \/home\/$1\/public_html;\r\n\r\n  try_files $2 =404;\r\n  fastcgi_split_path_info ^(.+\\.php)(.*)$;\r\n  fastcgi_pass unix:\/var\/run\/php5-fpm.sock;\r\n  fastcgi_index index.php;\r\n  fastcgi_intercept_errors on;\r\n  include fastcgi_params;\r\n\r\n  fastcgi_param SCRIPT_NAME \/~$1$fastcgi_script_name;\r\n}\r\n\r\n# Home directories\r\nlocation ~ ^\/~(.+?)(\/.*)?$ {\r\n  alias \/home\/$1\/public_html$2;\r\n}\r\n<\/pre>\n<p>You can see here the two locations that match the user directories. The first one matches the PHP scripts\u00a0and passes them\u00a0to the FastCGI process manager. For more information, see\u00a0<a href=\"http:\/\/wiki.nginx.org\/PHPFcgiExample\">PHPFcgiExample<\/a>. Note that I use a UNIX instead of an INET socket. Why would you bother IP on localhost when you can use an UNIX socket? I also set\u00a0the SCRIPT_NAME parameter to ensure that it is derived correctly from the user URL. This need to be fixed for pages\u00a0that\u00a0point to themselves. I also had to restart\u00a0<em>php5-fpm<\/em>\u00a0to ensure that the changes were taken into account.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I use nginx as my main HTTP server. \u00a0I want the users to be able to publish their own pages in a special directory (public_html) within their home directory. They should also be able to use PHP\u00a0scripts if they want &hellip; <a href=\"https:\/\/hauweele.net\/~gawen\/blog\/?p=458\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[465,462,461,466,460,231,463,464],"class_list":["post-458","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-directory","tag-fastcgi","tag-fpm","tag-home","tag-nginx","tag-php","tag-script_name","tag-user"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=458"}],"version-history":[{"count":0,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/458\/revisions"}],"wp:attachment":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}