安装Nginx

Nginx(读作in gen ex)是Web服务器,类似Apache,不过更容易配置,而且使用系统内存通常更少。我没有时间详细介绍Nginx,不过我想告诉你如何在你的服务器中安装Nginx,以及如何把相应的请求转发给PHP-FPM进程池。

Centos7安装Nginx 有两种方法

  1. 通过yum安装
  2. 手动下载安装包解压安装

本文采用第一种安装方式,通过yum安装
当然,直接通过 yum install nginx 肯定是不行的,因为yum没有nginx,所以首先把 nginx 的源加入 yum中

一、sudo yum install epel-release 命令,添加CentOS7 EPEL存储库

[root@localhost ~]# sudo yum install epel-release
Loaded plugins: fastestmirror
base                                                                                             | 3.6 kB  00:00:00
epel                                                                                             | 3.2 kB  00:00:00
extras                                                                                           | 3.4 kB  00:00:00
updates                                                                                          | 3.4 kB  00:00:00
(1/7): base/7/x86_64/group_gz                                                                    | 166 kB  00:00:00
(2/7): epel/x86_64/group_gz                                                                      |  88 kB  00:00:00
(3/7): epel/x86_64/updateinfo                                                                    | 943 kB  00:00:00
(4/7): extras/7/x86_64/primary_db                                                                | 187 kB  00:00:00
(5/7): epel/x86_64/primary                                                                       | 3.6 MB  00:00:00
(6/7): base/7/x86_64/primary_db                                                                  | 5.9 MB  00:00:00
(7/7): updates/7/x86_64/primary_db                                                               | 5.2 MB  00:00:00
Determining fastest mirrors
epel                                                                                                        12687/12687
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                          Arch                       Version                     Repository                Size
========================================================================================================================
Installing:
 epel-release                     noarch                     7-11                        epel                      15 k

Transaction Summary
========================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]:

键入 “y” 回车,安装成功

Downloading packages:
epel-release-7-11.noarch.rpm                                                                     |  15 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : epel-release-7-11.noarch                                                                             1/1
warning: /etc/yum.repos.d/epel.repo created as /etc/yum.repos.d/epel.repo.rpmnew
 Verifying  : epel-release-7-11.noarch                                                                             1/1

Installed:
 epel-release.noarch 0:7-11

Complete!

二、sudo yum install nginx 命令,现在,Nginx的存储库安装在服务器上,然后安装Web服务器。

[root@localhost ~]# sudo yum install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.12.2-2.el7 will be installed
--> Processing Dependency: nginx-filesystem = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64
--> Processing Dependency: nginx-all-modules = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-2.el7.x86_64
--> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: 1:nginx-1.12.2-2.el7.x86_64
--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-2.el7.x86_64
--> Running transaction check
---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed
---> Package nginx-all-modules.noarch 1:1.12.2-2.el7 will be installed
--> Processing Dependency: nginx-mod-stream = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
--> Processing Dependency: nginx-mod-mail = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
--> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
--> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
---> Package nginx-filesystem.noarch 1:1.12.2-2.el7 will be installed
---> Package openssl-libs.x86_64 1:1.0.1e-60.el7_3.1 will be updated
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-60.el7_3.1 for package: 1:openssl-1.0.1e-60.el7_3.1.x86_64
---> Package openssl-libs.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 will be installed
--> Processing Dependency: GeoIP for package: 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64
---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7 will be installed
--> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64
--> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64
---> Package nginx-mod-http-perl.x86_64 1:1.12.2-2.el7 will be installed
---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 will be installed
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64
--> Processing Dependency: libxslt.so.1()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64
--> Processing Dependency: libexslt.so.0()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64
---> Package nginx-mod-mail.x86_64 1:1.12.2-2.el7 will be installed
---> Package nginx-mod-stream.x86_64 1:1.12.2-2.el7 will be installed
---> Package openssl.x86_64 1:1.0.1e-60.el7_3.1 will be updated
---> Package openssl.x86_64 1:1.0.2k-12.el7 will be an update
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-11.el7 will be installed
---> Package gd.x86_64 0:2.0.35-26.el7 will be installed
--> Processing Dependency: libpng15.so.15(PNG15_0)(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libjpeg.so.62(LIBJPEG_6.2)(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libpng15.so.15()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libjpeg.so.62()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libfontconfig.so.1()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64
--> Processing Dependency: libX11.so.6()(64bit) for package: gd-2.0.35-26.el7.x86_64
---> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed
--> Running transaction check
---> Package fontconfig.x86_64 0:2.10.95-11.el7 will be installed
--> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.10.95-11.el7.x86_64
--> Processing Dependency: font(:lang=en) for package: fontconfig-2.10.95-11.el7.x86_64
---> Package libX11.x86_64 0:1.6.5-1.el7 will be installed
--> Processing Dependency: libX11-common >= 1.6.5-1.el7 for package: libX11-1.6.5-1.el7.x86_64
--> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.5-1.el7.x86_64
---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed
---> Package libjpeg-turbo.x86_64 0:1.2.90-5.el7 will be installed
---> Package libpng.x86_64 2:1.5.13-7.el7_2 will be installed
--> Running transaction check
---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed
---> Package libX11-common.noarch 0:1.6.5-1.el7 will be installed
---> Package libxcb.x86_64 0:1.12-1.el7 will be installed
--> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.12-1.el7.x86_64
---> Package lyx-fonts.noarch 0:2.2.3-1.el7 will be installed
--> Running transaction check
---> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed
--> Finished Dependency Resolution
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                                   Arch                 Version                        Repository          Size
========================================================================================================================
Installing:
 nginx                                     x86_64               1:1.12.2-2.el7                 epel               530 k
Installing for dependencies:
 GeoIP                                     x86_64               1.5.0-11.el7                   base               1.1 M
 fontconfig                                x86_64               2.10.95-11.el7                 base               229 k
 fontpackages-filesystem                   noarch               1.44-8.el7                     base               9.9 k
 gd                                        x86_64               2.0.35-26.el7                  base               146 k
 gperftools-libs                           x86_64               2.6.1-1.el7                    base               272 k
 libX11                                    x86_64               1.6.5-1.el7                    base               606 k
 libX11-common                             noarch               1.6.5-1.el7                    base               164 k
 libXau                                    x86_64               1.0.8-2.1.el7                  base                29 k
 libXpm                                    x86_64               3.5.12-1.el7                   base                55 k
 libjpeg-turbo                             x86_64               1.2.90-5.el7                   base               134 k
 libpng                                    x86_64               2:1.5.13-7.el7_2               base               213 k
 libxcb                                    x86_64               1.12-1.el7                     base               211 k
 libxslt                                   x86_64               1.1.28-5.el7                   base               242 k
 lyx-fonts                                 noarch               2.2.3-1.el7                    epel               159 k
 nginx-all-modules                         noarch               1:1.12.2-2.el7                 epel                16 k
 nginx-filesystem                          noarch               1:1.12.2-2.el7                 epel                17 k
 nginx-mod-http-geoip                      x86_64               1:1.12.2-2.el7                 epel                23 k
 nginx-mod-http-image-filter               x86_64               1:1.12.2-2.el7                 epel                26 k
 nginx-mod-http-perl                       x86_64               1:1.12.2-2.el7                 epel                36 k
 nginx-mod-http-xslt-filter                x86_64               1:1.12.2-2.el7                 epel                26 k
 nginx-mod-mail                            x86_64               1:1.12.2-2.el7                 epel                54 k
 nginx-mod-stream                          x86_64               1:1.12.2-2.el7                 epel                76 k
Updating for dependencies:
 openssl                                   x86_64               1:1.0.2k-12.el7                base               492 k
 openssl-libs                              x86_64               1:1.0.2k-12.el7                base               1.2 M

Transaction Summary
========================================================================================================================
Install  1 Package  (+22 Dependent packages)
Upgrade             (  2 Dependent packages)

Total download size: 5.9 M
Is this ok [y/d/N]:

键入 “y” 回车,安装完成

Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/25): fontconfig-2.10.95-11.el7.x86_64.rpm                                                     | 229 kB  00:00:00
(2/25): fontpackages-filesystem-1.44-8.el7.noarch.rpm                                            | 9.9 kB  00:00:00
(3/25): gd-2.0.35-26.el7.x86_64.rpm                                                              | 146 kB  00:00:00
(4/25): gperftools-libs-2.6.1-1.el7.x86_64.rpm                                                   | 272 kB  00:00:00
(5/25): libX11-1.6.5-1.el7.x86_64.rpm                                                            | 606 kB  00:00:00
(6/25): libX11-common-1.6.5-1.el7.noarch.rpm                                                     | 164 kB  00:00:00
(7/25): libXau-1.0.8-2.1.el7.x86_64.rpm                                                          |  29 kB  00:00:00
(8/25): libXpm-3.5.12-1.el7.x86_64.rpm                                                           |  55 kB  00:00:00
(9/25): libjpeg-turbo-1.2.90-5.el7.x86_64.rpm                                                    | 134 kB  00:00:00
(10/25): libpng-1.5.13-7.el7_2.x86_64.rpm                                                        | 213 kB  00:00:00
(11/25): libxcb-1.12-1.el7.x86_64.rpm                                                            | 211 kB  00:00:00
(12/25): libxslt-1.1.28-5.el7.x86_64.rpm                                                         | 242 kB  00:00:00
(13/25): lyx-fonts-2.2.3-1.el7.noarch.rpm                                                        | 159 kB  00:00:00
(14/25): nginx-all-modules-1.12.2-2.el7.noarch.rpm                                               |  16 kB  00:00:00
(15/25): nginx-filesystem-1.12.2-2.el7.noarch.rpm                                                |  17 kB  00:00:00
(16/25): nginx-1.12.2-2.el7.x86_64.rpm                                                           | 530 kB  00:00:00
(17/25): nginx-mod-http-geoip-1.12.2-2.el7.x86_64.rpm                                            |  23 kB  00:00:00
(18/25): GeoIP-1.5.0-11.el7.x86_64.rpm                                                           | 1.1 MB  00:00:00
(19/25): nginx-mod-http-perl-1.12.2-2.el7.x86_64.rpm                                             |  36 kB  00:00:00
(20/25): nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64.rpm                                      |  26 kB  00:00:00
(21/25): nginx-mod-mail-1.12.2-2.el7.x86_64.rpm                                                  |  54 kB  00:00:00
(22/25): nginx-mod-stream-1.12.2-2.el7.x86_64.rpm                                                |  76 kB  00:00:00
(23/25): nginx-mod-http-image-filter-1.12.2-2.el7.x86_64.rpm                                     |  26 kB  00:00:00
(24/25): openssl-1.0.2k-12.el7.x86_64.rpm                                                        | 492 kB  00:00:00
(25/25): openssl-libs-1.0.2k-12.el7.x86_64.rpm                                                   | 1.2 MB  00:00:00
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   9.6 MB/s | 5.9 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : fontpackages-filesystem-1.44-8.el7.noarch                                                           1/27
  Updating   : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                 2/27
  Updating   : 1:openssl-1.0.2k-12.el7.x86_64                                                                      3/27
  Installing : lyx-fonts-2.2.3-1.el7.noarch                                                                        4/27
  Installing : fontconfig-2.10.95-11.el7.x86_64                                                                    5/27
  Installing : gperftools-libs-2.6.1-1.el7.x86_64                                                                  6/27
  Installing : GeoIP-1.5.0-11.el7.x86_64                                                                           7/27
  Installing : libXau-1.0.8-2.1.el7.x86_64                                                                         8/27
  Installing : libxcb-1.12-1.el7.x86_64                                                                            9/27
  Installing : libX11-common-1.6.5-1.el7.noarch                                                                   10/27
  Installing : libX11-1.6.5-1.el7.x86_64                                                                          11/27
  Installing : libXpm-3.5.12-1.el7.x86_64                                                                         12/27
  Installing : libxslt-1.1.28-5.el7.x86_64                                                                        13/27
  Installing : 1:nginx-filesystem-1.12.2-2.el7.noarch                                                             14/27
  Installing : 2:libpng-1.5.13-7.el7_2.x86_64                                                                     15/27
  Installing : libjpeg-turbo-1.2.90-5.el7.x86_64                                                                  16/27
  Installing : gd-2.0.35-26.el7.x86_64                                                                            17/27
  Installing : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64                                                   18/27
  Installing : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64                                                         19/27
  Installing : 1:nginx-mod-stream-1.12.2-2.el7.x86_64                                                             20/27
  Installing : 1:nginx-mod-mail-1.12.2-2.el7.x86_64                                                               21/27
  Installing : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64                                                          22/27
  Installing : 1:nginx-1.12.2-2.el7.x86_64                                                                        23/27
  Installing : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64                                                  24/27
  Installing : 1:nginx-all-modules-1.12.2-2.el7.noarch                                                            25/27
  Cleanup    : 1:openssl-1.0.1e-60.el7_3.1.x86_64                                                                 26/27
  Cleanup    : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64                                                            27/27
  Verifying  : libX11-1.6.5-1.el7.x86_64                                                                           1/27
  Verifying  : lyx-fonts-2.2.3-1.el7.noarch                                                                        2/27
  Verifying  : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64                                                    3/27
  Verifying  : libjpeg-turbo-1.2.90-5.el7.x86_64                                                                   4/27
  Verifying  : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64                                                          5/27
  Verifying  : 1:nginx-1.12.2-2.el7.x86_64                                                                         6/27
  Verifying  : libxcb-1.12-1.el7.x86_64                                                                            7/27
  Verifying  : 2:libpng-1.5.13-7.el7_2.x86_64                                                                      8/27
  Verifying  : 1:openssl-libs-1.0.2k-12.el7.x86_64                                                                 9/27
  Verifying  : 1:nginx-mod-stream-1.12.2-2.el7.x86_64                                                             10/27
  Verifying  : fontpackages-filesystem-1.44-8.el7.noarch                                                          11/27
  Verifying  : 1:nginx-all-modules-1.12.2-2.el7.noarch                                                            12/27
  Verifying  : libXpm-3.5.12-1.el7.x86_64                                                                         13/27
  Verifying  : 1:nginx-filesystem-1.12.2-2.el7.noarch                                                             14/27
  Verifying  : libxslt-1.1.28-5.el7.x86_64                                                                        15/27
  Verifying  : 1:nginx-mod-mail-1.12.2-2.el7.x86_64                                                               16/27
  Verifying  : gd-2.0.35-26.el7.x86_64                                                                            17/27
  Verifying  : libX11-common-1.6.5-1.el7.noarch                                                                   18/27
  Verifying  : libXau-1.0.8-2.1.el7.x86_64                                                                        19/27
  Verifying  : GeoIP-1.5.0-11.el7.x86_64                                                                          20/27
  Verifying  : fontconfig-2.10.95-11.el7.x86_64                                                                   21/27
  Verifying  : gperftools-libs-2.6.1-1.el7.x86_64                                                                 22/27
  Verifying  : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64                                                          23/27
  Verifying  : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64                                                  24/27
  Verifying  : 1:openssl-1.0.2k-12.el7.x86_64                                                                     25/27
  Verifying  : 1:openssl-1.0.1e-60.el7_3.1.x86_64                                                                 26/27
  Verifying  : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64                                                            27/27

Installed:
  nginx.x86_64 1:1.12.2-2.el7

Dependency Installed:
  GeoIP.x86_64 0:1.5.0-11.el7                             fontconfig.x86_64 0:2.10.95-11.el7
  fontpackages-filesystem.noarch 0:1.44-8.el7             gd.x86_64 0:2.0.35-26.el7
  gperftools-libs.x86_64 0:2.6.1-1.el7                    libX11.x86_64 0:1.6.5-1.el7
  libX11-common.noarch 0:1.6.5-1.el7                      libXau.x86_64 0:1.0.8-2.1.el7
  libXpm.x86_64 0:3.5.12-1.el7                            libjpeg-turbo.x86_64 0:1.2.90-5.el7
  libpng.x86_64 2:1.5.13-7.el7_2                          libxcb.x86_64 0:1.12-1.el7
  libxslt.x86_64 0:1.1.28-5.el7                           lyx-fonts.noarch 0:2.2.3-1.el7
  nginx-all-modules.noarch 1:1.12.2-2.el7                 nginx-filesystem.noarch 1:1.12.2-2.el7
  nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7              nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7
  nginx-mod-http-perl.x86_64 1:1.12.2-2.el7               nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7
  nginx-mod-mail.x86_64 1:1.12.2-2.el7                    nginx-mod-stream.x86_64 1:1.12.2-2.el7

Dependency Updated:
  openssl.x86_64 1:1.0.2k-12.el7                           openssl-libs.x86_64 1:1.0.2k-12.el7

Complete!

三、sudo service nginx start 命令,安装成功后,启动Nginx在你的VPS:

[root@localhost ~]# sudo service nginx start
Redirecting to /bin/systemctl start  nginx.service

四、curl -i localhost 验证安装顺利,提示:Welcome to nginx!

[root@localhost ~]# curl -i localhost
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Wed, 26 Sep 2018 07:14:30 GMT
Content-Type: text/html
Content-Length: 3700
Last-Modified: Tue, 06 Mar 2018 09:26:21 GMT
Connection: keep-alive
ETag: "5a9e5ebd-e74"
Accept-Ranges: bytes

<!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">
    <head>
        <title>Test Page for the Nginx HTTP Server on Fedora</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">
            /*<![CDATA[*/
            body {
                background-color: #fff;
                color: #000;
                font-size: 0.9em;
                font-family: sans-serif,helvetica;
                margin: 0;
                padding: 0;
            }
            :link {
                color: #c00;
            }
            :visited {
                color: #c00;
            }
            a:hover {
                color: #f50;
            }
            h1 {
                text-align: center;
                margin: 0;
                padding: 0.6em 2em 0.4em;
                background-color: #294172;
                color: #fff;
                font-weight: normal;
                font-size: 1.75em;
                border-bottom: 2px solid #000;
            }
            h1 strong {
                font-weight: bold;
                font-size: 1.5em;
            }
            h2 {
                text-align: center;
                background-color: #3C6EB4;
                font-size: 1.1em;
                font-weight: bold;
                color: #fff;
                margin: 0;
                padding: 0.5em;
                border-bottom: 2px solid #294172;
            }
            hr {
                display: none;
            }
            .content {
                padding: 1em 5em;
            }
            .alert {
                border: 2px solid #000;
            }

            img {
                border: 2px solid #fff;
                padding: 2px;
                margin: 2px;
            }
            a:hover img {
                border: 2px solid #294172;
            }
            .logos {
                margin: 1em;
                text-align: center;
            }
            /*]]>*/
        </style>
    </head>

    <body>
        <h1>Welcome to <strong>nginx</strong> on Fedora!</h1>

        <div class="content">
            <p>This page is used to test the proper operation of the
            <strong>nginx</strong> HTTP server after it has been
            installed. If you can read this page, it means that the
            web server installed at this site is working
            properly.</p>

            <div class="alert">
                <h2>Website Administrator</h2>
                <div class="content">
                    <p>This is the default <tt>index.html</tt> page that
                    is distributed with <strong>nginx</strong> on
                    Fedora.  It is located in
                    <tt>/usr/share/nginx/html</tt>.</p>

                    <p>You should now put your content in a location of
                    your choice and edit the <tt>root</tt> configuration
                    directive in the <strong>nginx</strong>
                    configuration file
                    <tt>/etc/nginx/nginx.conf</tt>.</p>

                </div>
            </div>

            <div class="logos">
                <a href="http://nginx.net/"><img
                    src="nginx-logo.png"
                    alt="[ Powered by nginx ]"
                    width="121" height="32" /></a>

                <a href="http://fedoraproject.org/"><img
                    src="poweredby.png"
                    alt="[ Powered by Fedora ]"
                    width="88" height="31" /></a>
            </div>
        </div>
    </body>
</html>

也可以通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页面,如下图:

验证安装成功.png

五、Nginx常用操作

查看nginx版本

[root@localhost ~]# nginx -v
nginx version: nginx/1.12.2

查看默认安装目录

[root@localhost ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz

以下是Nginx的默认路径:

  1. Nginx配置路径:/etc/nginx/
  2. PID目录:/var/run/nginx.pid
  3. 错误日志:/var/log/nginx/error.log
  4. 访问日志:/var/log/nginx/access.log
  5. 默认站点目录:/usr/share/nginx/html
    事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 及/etc/nginx/conf.d/default.conf 中查询到

是否安装正常

[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动nginx
命令一:nginx
命令二:
service nginx start #centos6

systemctl start nginx.service #centos7

[root@localhost ~]# service nginx start
Redirecting to /bin/systemctl start  nginx.service

停止nginx
快速停止或关闭Nginx:nginx -s stop
正常停止或关闭Nginx:nginx -s quit

[root@localhost ~]# nginx -s stop

重启nginx

[root@localhost ~]# 

CentOS 7 开机启动Nginx

[root@localhost ~]# sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

Linux查看公网IP

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,634评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,951评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,427评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,770评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,835评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,799评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,768评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,544评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,979评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,271评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,427评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,121评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,756评论 3 324
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,375评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,579评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,410评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,315评论 2 352

推荐阅读更多精彩内容