LoginSignup
0
0

More than 1 year has passed since last update.

Nginxでhtml表示する方法

Last updated at Posted at 2022-08-01

はじめに

Apacheでhtml表記はできましたが、
Nginxでのhtml表記に少し手こずったため記録します。
※日本語の文字化けも解決

仕様

  • Linux
  • Amazon-linux2
  • nginx

Nginxのインストール

# yum search nginx
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
=================================== N/S matched: nginx ====================================
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver

  Name and summary matches only, use "search all" for everything.

# amazon-linux-extras list | grep nginx
38  nginx1                   available    [ =stable ]

# amazon-linux-extras info nginx1
nginx1 recommends nginx                      # yum install nginx

# sudo amazon-linux-extras install nginx1

インストールが始まり、問題なく終われば
Nginxのインストール完了。

Nginx起動確認

# sudo systemctl start nginx
# sudo systemctl status nginx
# sudo systemctl enable nginx

問題なく起動していればOK。

htmlファイル作成

# cd /usr/share/nginx/html
# sudo vi 好きなファイル名.html
# sudo systemctl restart nginx

NginxはApacheとはhtmlのファイル位置が違う。
viでファイル内編集。
ファイル内を編集した後は
Nginxをrestartして
http://パブリックIP/好きなファイル名.html」にアクセス。

日本語が文字化けした場合

作成したhtmlファイルが文字化けしていた場合、
Nginxの設定ファイルに
下記を追加すると、解決される。
※「nginx.conf」は/etc/nginx下にある。

nginx.conf
include             /etc/nginx/mime.types;
default_type        application/octet-stream;
charset UTF-8;
# sudo systemctl restart nginx

再起動で、日本語の文字化けが解決された!!

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