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.

NGINXのドキュメントルートを解説

Last updated at Posted at 2023-05-22

nginx系コマンド

用途 コマンド 補足
ステータス確認 systemctl status nginx ---
nginxリロード sudo systemctl reload nginx -
ドキュメルート sudo vi /etc/nginx/conf.d/default.conf -
nginx設定のチェック sudo nginx -t -

nginx ドキュメントルートとは

WEBページを表示するディレクトリやファイルの場所を指定する
構文 役割
location URIのパス単位の設定
location ~ .php$ nginxでPHPを動かす
server_name バーチャルサーバの名前
構文 役割
root ドキュメントルートのディレクトリ
index パスが/(ルート)の時、そのファイルにリダイレクトする
try_files $uri $uri/index.php;
構文 役割
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

include

server {
   一番最初のディレクトリ。※ルートディレクトリ
  root /var/www/abc;
  listen    80;
  server_name localhost;
   location / {
     index index.php;
     try_files $uri /index.php?$args;
  }
   error_page  500 502 503 504 /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;
    }
   location ~ \.php$ {
    fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_read_timeout 120s;
  }
}
server {
  root /usr/share/nginx/html;
  listen 80;
  server_name localhost;

  location /{
     index index.php;
   }

  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}
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?