Nginx - UserDirを有効にする2013/07/07 |
|
一般ユーザーが自身のホームディレクトリ内に置いたファイルをWebサイトとして公開できるようにします。
|
|
| [1] | Nginx の設定 |
|
[root@www ~]#
vi /etc/nginx/conf.d/default.conf
server {
listen 80 default_server;
server_name www.srv.world;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# server セクション内の適当な位置に設定を追記
location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
autoindex on;
}
/etc/rc.d/init.d/nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] |
| [2] | 一般ユーザーで自身のホームディレクトリにHTMLテストページを作成し、動作確認をします。 作成したテストページにWebブラウザでアクセスして、以下のようなページが表示されればOKです。 |
|
[cent@www ~]$ chmod 711 /home/cent [cent@www ~]$ mkdir ./public_html [cent@www ~]$ chmod 755 ./public_html
[cent@www ~]$
vi ./public_html/index.html <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> Nginx UserDir Test Page </div> </body> </html> |
|
| Sponsored Link |
|
|