0
0

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 3 years have passed since last update.

nginxのルートディレクトリ

Posted at

はじめに

nginxのルートディレクトリについて備忘録です。

ルートディレクトリの設定ファイル

$cat nginx.conf
    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html; ←ここで設定されている

ここを変更してみる。

$sudo mkdir /home/test
$sudo sed -i -e 's@/usr/share/nginx/html@/home/test@g' nginx.conf
    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /home/test;  ←変更された

nginxを再起動する

$sudo systemctl restart nginx

nginxの状態を確認

$sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2022-02-19 08:43:04 UTC; 33s ago
  Process: 32428 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 32424 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 32421 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 32431 (nginx)
   CGroup: /system.slice/nginx.service
           tq32431 nginx: master process /usr/sbin/nginx
           mq32432 nginx: worker process

ブラウザのアドレスバーにEC2のパブリックIPアドレスを入力

EC2のパブリックIPを確認

ec2-metadata | grep public-ip
public-ipv4: 3.8x.1xx.2xx

image.png

nginxの変更後のルートディレクトリにindex.htmlを配置する

sudo vi /home/test/index.html
<head>
</head>
<body>
<h1>nginx test</h1>
</body>

ブラウザのアドレスバーにEC2のパブリックIPアドレスを入力

image.png

おわりに

今回は、nginxのルートディレクトリを変更して、適当なindex.htmlを表示させてみました。
では、また。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?