nginxでユーザーディレクトリの下にpublic_htmlを作成する方法
nginxのデフォルトのドキュメントルートは/usr/share/nginx/htmlとなっている
これとは別に、/home/user1/public_htmlというディレクトリを作成し、
nginxで公開する
public_htmlディレクトリを作成
cd /home/user1 mkdir public_html
public_htmlディレクトリの権限設定
cd /home/user1/public_html
chown -R nginx:nginx .
find . -type d -exec chmod 700 {} +
find . -type f -exec chmod 600 {} +
chmod o+x /
chmod o+x /home
chmod o+x /home/user1
index.htmlを作成
vi /home/user1/public_html/index.html
index.htmlというファイルを新規作成
- index.html
<html> <p>This is index.html in /home/user1/public_html</p> </html>
index.htmlの中は、上記のようなものを書く
public_htmlの動作確認1
ブラウザで
http://IPアドレス
のようなURLにアクセスする
This is index.html in /home/user1/public_html
と表示されればOK
この時点ではnginxの設定がまだなので、
This is index.html in /home/user1/public_html
とは表示されないはず
nginxの.confを設定
default.confを作成
vi /etc/nginx/conf.d/default.conf
default.confを新規作成
もしも、default.confというファイルがもともと存在する場合は、
default.confをdefault.conf.originalのようなファイル名にリネームしてバックアップしておく
そして、空のdefault.confを新規作成する
default.confを設定
- default.conf
server { listen 80 default_server; root /home/user1/public_html; index index.html; }
nginxを再起動
nginx -t systemctl restart nginx
nginxのサービスを再起動
public_htmlの動作確認2
ブラウザで
http://IPアドレス
のようなURLにアクセスする
This is index.html in user1/public_html
と表示されればOK