今更ですがApacheからNginxへ移行しようかなと思って勉強を始めてみました。
nginx
https://nginx.org/en/
環境
・CentOS Linux release 8.2.2004 (Core)
・Kernel 4.18.0-193.6.3.el8_2.x86_64
- Install
- 自動起動の設定と起動
- Firewallの許可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
[root@centos8 ~]# dnf info nginx Available Packages Name : nginx Epoch : 1 Version : 1.14.1 Release : 9.module_el8.0.0+184+e34fea82 Architecture : x86_64 Size : 570 k Source : nginx-1.14.1-9.module_el8.0.0+184+e34fea82.src.rpm Repository : AppStream Summary : A high performance web server and reverse proxy server URL : http://nginx.org/ License : 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. [root@centos8 ~]# dnf -y install nginx Last metadata expiration check: 1:38:20 ago on Tue Jul 14 15:19:46 2020. Dependencies resolved. ======================================================================================== Package Arch Version Repo Size ======================================================================================== Installing: nginx x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 570 k Installing dependencies: nginx-all-modules noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 23 k nginx-filesystem noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 24 k nginx-mod-http-image-filter x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 35 k nginx-mod-http-perl x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 45 k nginx-mod-http-xslt-filter x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 33 k nginx-mod-mail x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 64 k nginx-mod-stream x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82 AppStream 85 k Enabling module streams: nginx 1.14 Transaction Summary ======================================================================================== Install 8 Packages Total download size: 881 k Installed size: 2.0 M Downloading Packages: (1/8): nginx-filesystem-1.14.1-9.module_el8.0.0+184+e34 49 kB/s | 24 kB 00:00 (2/8): nginx-all-modules-1.14.1-9.module_el8.0.0+184+e3 47 kB/s | 23 kB 00:00 (3/8): nginx-mod-http-image-filter-1.14.1-9.module_el8. 670 kB/s | 35 kB 00:00 (4/8): nginx-mod-http-perl-1.14.1-9.module_el8.0.0+184+ 862 kB/s | 45 kB 00:00 (5/8): nginx-1.14.1-9.module_el8.0.0+184+e34fea82.x86_6 925 kB/s | 570 kB 00:00 (6/8): nginx-mod-http-xslt-filter-1.14.1-9.module_el8.0 482 kB/s | 33 kB 00:00 (7/8): nginx-mod-mail-1.14.1-9.module_el8.0.0+184+e34fe 926 kB/s | 64 kB 00:00 (8/8): nginx-mod-stream-1.14.1-9.module_el8.0.0+184+e34 2.0 MB/s | 85 kB 00:00 ---------------------------------------------------------------------------------------- Total 477 kB/s | 881 kB 00:01 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noar 1/8 Installing : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noar 1/8 Installing : nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e3 2/8 Running scriptlet: nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e3 2/8 Installing : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x 3/8 Running scriptlet: nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x 3/8 Installing : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34 4/8 Running scriptlet: nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34 4/8 Installing : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 5/8 Running scriptlet: nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 5/8 Installing : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noa 6/8 Installing : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 7/8 Running scriptlet: nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 7/8 Installing : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_ 8/8 Running scriptlet: nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_ 8/8 Verifying : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 1/8 Verifying : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noa 2/8 Verifying : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noar 3/8 Verifying : nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e3 4/8 Verifying : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x 5/8 Verifying : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34 6/8 Verifying : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 7/8 Verifying : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_ 8/8 Installed: nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 Complete! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[root@centos8 ~]# systemctl list-unit-files | grep nginx nginx.service disabled [root@centos8 ~]# systemctl enable nginx Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service -> /usr/lib/systemd/system/nginx.service. [root@centos8 ~]# systemctl start nginx [root@centos8 ~]# systemctl status nginx * nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disab> Active: active (running) since Tue 2020-07-14 17:07:16 JST; 8s ago Process: 35027 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 35025 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 35022 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCC> Main PID: 35028 (nginx) Tasks: 5 (limit: 49603) Memory: 15.8M CGroup: /system.slice/nginx.service |-35028 nginx: master process /usr/sbin/nginx |-35029 nginx: worker process |-35030 nginx: worker process |-35031 nginx: worker process `-35032 nginx: worker process Jul 14 17:07:16 centos8.rootlinks.net systemd[1]: Starting The nginx HTTP and reverse p> Jul 14 17:07:16 centos8.rootlinks.net nginx[35025]: nginx: the configuration file /etc/> Jul 14 17:07:16 centos8.rootlinks.net nginx[35025]: nginx: configuration file /etc/ngin> Jul 14 17:07:16 centos8.rootlinks.net systemd[1]: Started The nginx HTTP and reverse pr> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@centos8 ~]# firewall-cmd --permanent --add-service=http success [root@centos8 ~]# firewall-cmd --reload success [root@centos8 ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens160 sources: services: cockpit dhcpv6-client http ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: |
http://IP_Address/ にアクセスすればトップページが表示されます。
左はトップページ、右は404のエラー画面です。
おまけ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
[root@centos8 ~]# nginx -v nginx version: nginx/1.14.1 [root@centos8 ~]# nginx -h nginx version: nginx/1.14.1 Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/share/nginx/) -c filename : set configuration file (default: /etc/nginx/nginx.conf) -g directives : set global directives out of configuration file [root@centos8 ~]# nginx -V nginx version: nginx/1.14.1 built by gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) built with OpenSSL 1.1.1 FIPS 11 Sep 2018 (running with OpenSSL 1.1.1c FIPS 28 May 2019) TLS SNI support enabled configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' [root@centos8 ~]# curl -I http://192.168.1.1 HTTP/1.1 200 OK Server: nginx/1.14.1 Date: Tue, 14 Jul 2020 08:16:33 GMT Content-Type: text/html Content-Length: 4057 Last-Modified: Mon, 07 Oct 2019 21:16:24 GMT Connection: keep-alive ETag: "5d9bab28-fd9" Accept-Ranges: bytes |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
[root@centos8 ~]# repoquery --list nginx /etc/logrotate.d/nginx /etc/nginx/fastcgi.conf /etc/nginx/fastcgi.conf.default /etc/nginx/fastcgi_params /etc/nginx/fastcgi_params.default /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/mime.types /etc/nginx/mime.types.default /etc/nginx/nginx.conf /etc/nginx/nginx.conf.default /etc/nginx/scgi_params /etc/nginx/scgi_params.default /etc/nginx/uwsgi_params /etc/nginx/uwsgi_params.default /etc/nginx/win-utf /usr/bin/nginx-upgrade /usr/lib/.build-id /usr/lib/.build-id/2d /usr/lib/.build-id/2d/da6018ae12edb856ad3d2cf61bf586b6b4873c /usr/lib/systemd/system/nginx.service /usr/lib64/nginx/modules /usr/sbin/nginx /usr/share/doc/nginx /usr/share/doc/nginx/CHANGES /usr/share/doc/nginx/README /usr/share/doc/nginx/README.dynamic /usr/share/licenses/nginx /usr/share/licenses/nginx/LICENSE /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx-upgrade.8.gz /usr/share/man/man8/nginx.8.gz /usr/share/nginx/html/404.html /usr/share/nginx/html/50x.html /usr/share/nginx/html/index.html /usr/share/nginx/html/nginx-logo.png /usr/share/nginx/html/poweredby.png /usr/share/vim/vimfiles/ftdetect/nginx.vim /usr/share/vim/vimfiles/indent/nginx.vim /usr/share/vim/vimfiles/syntax/nginx.vim /var/lib/nginx /var/lib/nginx/tmp /var/log/nginx |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
[root@centos8 ~]# cat /etc/nginx/nginx.conf # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; 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 { } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers PROFILE=SYSTEM; # ssl_prefer_server_ciphers on; # # # 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 { # } # } } [root@centos8 ~]# ls -l /usr/share/nginx/modules/ total 20 -rw-r--r--. 1 root root 72 Oct 8 2019 mod-http-image-filter.conf -rw-r--r--. 1 root root 64 Oct 8 2019 mod-http-perl.conf -rw-r--r--. 1 root root 71 Oct 8 2019 mod-http-xslt-filter.conf -rw-r--r--. 1 root root 59 Oct 8 2019 mod-mail.conf -rw-r--r--. 1 root root 61 Oct 8 2019 mod-stream.conf [root@centos8 ~]# ls -l /usr/share/nginx/html total 24 -rw-r--r--. 1 root root 3971 Oct 8 2019 404.html -rw-r--r--. 1 root root 4020 Oct 8 2019 50x.html -rw-r--r--. 1 root root 4057 Oct 8 2019 index.html -rw-r--r--. 1 root root 368 Oct 8 2019 nginx-logo.png -rw-r--r--. 1 root root 4148 Oct 8 2019 poweredby.png |