LINEで現役エンジニアに直接質問してみよう!登録無料

NginxをCentOS 7.6にNginxをインストールする方法! firewalldとsystemctlの操作方法も少し解説

$ sudo yum update
$ sudo yum install nginx
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <[email protected]>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
$ systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
$ systemctl start nginx
$ systemctl status nginx
 nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-07-17 15:22:35 JST; 6s ago
  Process: 16584 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 16581 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 16580 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 16586 (nginx)
   CGroup: /system.slice/nginx.service
           ├─16586 nginx: master process /usr/sbin/nginx
           └─16587 nginx: worker process

Jul 17 15:22:35 133-130-90-28 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jul 17 15:22:35 133-130-90-28 nginx[16581]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jul 17 15:22:35 133-130-90-28 nginx[16581]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jul 17 15:22:35 133-130-90-28 systemd[1]: Started The nginx HTTP and reverse proxy server.
$ curl localhost
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
.
.
.
    </body>
</html>
$ firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: ssh dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:
$ systemctl stop firewalld
この記事を書いた人

自身がプログラミングを独学で勉強し始めて躓いた経験を元に、これから勉強をする人に向けに「イラスト多めでわかりやすい記事」にこだわって情報を発信しています。

現在はフルスタックエンジニアとしてサービス開発などのお仕事をしています。