Fedora Workstationにnginxをインストール

Fedora Workstationにnginxをインストール

Fedora Workstationにnginxをインストールする手順となります。firewallの問題で少し問題が発生したのでメモしてます。

fedoraバージョン

fedora30

リポジトリの追加

## 最新のものをインストール
sudo dnf install http://nginx.org/packages/rhel/7/noarch/RPMS/nginx-release-rhel-7-0.el7.ngx.noarch.rpm

パッケージ情報確認

## 情報確認
sudo dnf info nginx

## 結果(認識できていれば問題なし)
利用可能なパッケージ
Name         : nginx
エポック     : 1
Version      : 1.16.1
リリース     : 1.fc30
Architecture : x86_64
Size         : 548 k
ソース       : nginx-1.16.1-1.fc30.src.rpm
Repository   : updates
Summary      : A high performance web server and reverse proxy server
URL          : http://nginx.org/
ライセンス   : BSD
Description  : Nginx is a web server and a reverse proxy server for HTTP, SMTP,
             : POP3 and IMAP protocols, with a strong focus on high concurrency,
             : performance and low memory usage.

nginxのインストール

インストールを行う

## インストール
sudo dnf install nginx

## バージョン確認
nginx -v
nginx version: nginx/1.16.1

## 自動起動
sudo systemctl enable nginx

nginx起動

## 起動
sudo systemctl start nginx

## 状態確認
sudo systemctl status nginx
   
Active: active (running) となっていればOK

nginx 動作確認

## 動作確認
curl -I http://localhost

## 結果 200コードが返ってきているのでOK
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Sun, 25 Aug 2019 06:59:03 GMT
Content-Type: text/html
Content-Length: 5683
Last-Modified: Thu, 04 Oct 2018 17:44:09 GMT
Connection: keep-alive
ETag: "5bb65169-1633"
Accept-Ranges: bytes

## ログの確認
sudo tail /var/log/nginx/access.log

## ログも問題なし
::1 - - [25/Aug/2019:15:59:03 +0900] "HEAD / HTTP/1.1" 200 0 "-" "curl/7.65.3" "-"

ブラウザより確認

ブラウザからhttp://IPアドレスと入力しアクセスできるか確認

できなかったので、設定を確認

## プロセスの確認
ps ax | grep nginx

## 結果 問題なし
 3299 ?        Ss     0:00 nginx: master process /usr/sbin/nginx
 3300 ?        S      0:00 nginx: worker process
 3373 pts/1    S+     0:00 grep --color=auto nginx

## portの確認
ss -natu | grep LISTEN | grep 80

## 結果 問題なし
tcp    LISTEN  0       128              0.0.0.0:80               0.0.0.0:*      
tcp    LISTEN  0       128                 [::]:80                  [::]:*
## 設定ファイル確認
sudo vi /etc/nginx/nginx.conf

## 内容 問題なさそう
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

SElinuxの確認

## selinux確認
sudo semanage port -l | grep 80

## 結果 問題なさそう
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000

firewall の設定っぽい。。なのでport とserviceを追加

## port80の追加
sudo firewall-cmd --add-port=80/tcp --zone=public --permanent

## serviceの追加
sudo firewall-cmd --add-service=http

一応、確認

## 設定portの確認
sudo firewall-cmd --list-ports

## 結果
1025-65535/udp 1025-65535/tcp 80/tcp
## serviceの確認
sudo firewall-cmd --list-service

## 結果
dhcpv6-client http https mdns samba-client ssh

firewallを再起動

## 再起動
sudo firewall-cmd --reload

これで問題なく表示された

後、現在の環境だとselinux無効にしても問題ないので無効に設定

## 設定ファイルの変更
sudo vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

reboot すれば変更完了