0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CentOS8のnginxでユーザディレクトリ(public_html)作成

0
Last updated at Posted at 2020-04-10

nginxのインストール

 dnf install nginx

ユーザディレクトリの設定

 cd /etc/nginx
 vi nginx.conf

ユーザディレクトリのロケーションを書き込む

  # for UserDir
  location ~ ^/~(.+?)(/.*)?$ {
    alias /home/$1/public_html$2;
  }

再起動

 systemctl restart nginx

ユーザディレクトリでphpを有効にする

phpのインストール

インストール

 dnf install php php-mbstring php-xml php-xmlrpc php-gd php-pdo php-mysqlnd php-json

確認

 php -v

nginxでphpを有効化

再起動

 systemctl restart nginx

有効になったことを確認する

 cd /usr/share/nginx/html
 echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/info.php

ブラウザからも下記のアドレスにアクセスして確認する
http://localhost/info.php

ユーザディレクトリの設定を変更する

 cd /etc/nginx
 vi nginx.conf
 location ~ ^/~([^/]+)/(.+\.php)$ {
 #    fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
 #
     alias /home/$1/public_html/$2;
     fastcgi_intercept_errors on;
     fastcgi_index  index.php;
     include        fastcgi_params;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     fastcgi_param  PATH_INFO $fastcgi_path_info;
     fastcgi_pass   php-fpm;
 }
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?