最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】CentOS 7中安装Nginx

CentOS crifan 4165浏览 0评论

折腾:

【已解决】把本地前端页面部署到在线Flask环境中

期间,需要先去到在线的CentOS 7:

[root@xx-general-01 ~]# lsb_release -a

LSB Version:    :core-4.1-amd64:core-4.1-noarch

Distributor ID: CentOS

Description:    CentOS Linux release 7.4.1708 (Core)

Release:        7.4.1708

Codename:       Core

[root@x-general-01 ~]# cat /etc/centos-release

CentOS Linux release 7.4.1708 (Core)

中安装Nginx

[root@xx-general-01 ~]# ll /etc/ng*

ls: cannot access /etc/ng*: No such file or directory

[root@xx-general-01 ~]# ll /usr/local/ngi*

ls: cannot access /usr/local/ngi*: No such file or directory

基本上确定了此处没有CentOS中没有安装nginx

centos install nginx

How To Install Nginx on CentOS 7 | DigitalOcean

CentOS 7 yum 安装 Nginx – CSDN博客

nginx服务器详细安装过程(使用yum 和 源码包两种安装方式,并说明其区别) – 傅毅 – SegmentFault 思否

Install | NGINX

看起来还是CentOS中用yum去安装,比较省事和方便。

[root@xxx-general-01 robotDemo]# yum -y install nginx

Loaded plugins: fastestmirror

base                                                                                                                                                               | 3.6 kB  00:00:00     

epel                                                                                                                                                               | 4.7 kB  00:00:00     

extras                                                                                                                                                             | 3.4 kB  00:00:00     

mongodb-org                                                                                                                                                        | 2.5 kB  00:00:00     

nux-dextop                                                                                                                                                         | 2.9 kB  00:00:00     

updates                                                                                                                                                            | 3.4 kB  00:00:00     

(1/2): epel/x86_64/updateinfo                                                                                                                                      | 917 kB  00:00:00     

(2/2): epel/x86_64/primary_db                                                                                                                                      | 6.3 MB  00:00:00     

Determining fastest mirrors

* nux-dextop: li.nux.ro

Resolving Dependencies

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Running transaction check

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx.x86_64 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: nginx-all-modules = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: nginx-filesystem = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-2.el7.x86_64

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-2.el7.x86_64

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Running transaction check

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package gperftools-libs.x86_64 0:2.4-8.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: libunwind.so.8()(64bit) for package: gperftools-libs-2.4-8.el7.x86_64

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-all-modules.noarch 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> 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

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> 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

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: nginx-mod-mail = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: nginx-mod-stream = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-filesystem.noarch 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Running transaction check

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package libunwind.x86_64 2:1.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-mod-http-perl.x86_64 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> 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

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> 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

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: libexslt.so.0()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Processing Dependency: libxslt.so.1()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-mod-mail.x86_64 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package nginx-mod-stream.x86_64 1:1.12.2-2.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> Running transaction check

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<-> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<> 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:

gperftools-libs                                            x86_64                                2.4-8.el7                                     base                                272 k

libunwind                                                  x86_64                                2:1.2-2.el7                                   base                                 57 k

libxslt                                                    x86_64                                1.1.28-5.el7                                  base                                242 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

Transaction Summary

==========================================================================================================================================================================================

Install  1 Package (+11 Dependent packages)

Total download size: 1.3 M

Installed size: 3.9 M

Downloading packages:

(1/12): libunwind-1.2-2.el7.x86_64.rpm                                                                                                                             |  57 kB  00:00:00     

(2/12): gperftools-libs-2.4-8.el7.x86_64.rpm                                                                                                                       | 272 kB  00:00:00     

(3/12): libxslt-1.1.28-5.el7.x86_64.rpm                                                                                                                            | 242 kB  00:00:00     

(4/12): nginx-all-modules-1.12.2-2.el7.noarch.rpm                                                                                                                  |  16 kB  00:00:00     

(5/12): nginx-filesystem-1.12.2-2.el7.noarch.rpm                                                                                                                   |  17 kB  00:00:00     

(6/12): nginx-mod-http-geoip-1.12.2-2.el7.x86_64.rpm                                                                                                               |  23 kB  00:00:00     

(7/12): nginx-mod-http-image-filter-1.12.2-2.el7.x86_64.rpm                                                                                                        |  26 kB  00:00:00     

(8/12): nginx-1.12.2-2.el7.x86_64.rpm                                                                                                                              | 530 kB  00:00:00     

(9/12): nginx-mod-http-perl-1.12.2-2.el7.x86_64.rpm                                                                                                                |  36 kB  00:00:00     

(10/12): nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64.rpm                                                                                                        |  26 kB  00:00:00     

(11/12): nginx-mod-mail-1.12.2-2.el7.x86_64.rpm                                                                                                                    |  54 kB  00:00:00     

(12/12): nginx-mod-stream-1.12.2-2.el7.x86_64.rpm                                                                                                                  |  76 kB  00:00:00     

<span style="font-family: Monaco; font-size: 12px; color: rgb(51, 51, 51);"–<—————————————————————————————————————————————————————————————-

Total                                                                                                                                                     5.9 MB/s | 1.3 MB  00:00:00     

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : 2:libunwind-1.2-2.el7.x86_64                                                                                                                                          1/12

  Installing : gperftools-libs-2.4-8.el7.x86_64                                                                                                                                      2/12

  Installing : libxslt-1.1.28-5.el7.x86_64                                                                                                                                           3/12

  Installing : 1:nginx-filesystem-1.12.2-2.el7.noarch                                                                                                                                4/12

  Installing : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64                                                                                                                             5/12

  Installing : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64                                                                                                                            6/12

  Installing : 1:nginx-mod-mail-1.12.2-2.el7.x86_64                                                                                                                                  7/12

  Installing : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64                                                                                                                      8/12

  Installing : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64                                                                                                                     9/12

  Installing : 1:nginx-all-modules-1.12.2-2.el7.noarch                                                                                                                              10/12

  Installing : 1:nginx-1.12.2-2.el7.x86_64                                                                                                                                          11/12

  Installing : 1:nginx-mod-stream-1.12.2-2.el7.x86_64                                                                                                                               12/12

  Verifying  : 1:nginx-filesystem-1.12.2-2.el7.noarch                                                                                                                                1/12

  Verifying  : gperftools-libs-2.4-8.el7.x86_64                                                                                                                                      2/12

  Verifying  : libxslt-1.1.28-5.el7.x86_64                                                                                                                                           3/12

  Verifying  : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64                                                                                                                             4/12

  Verifying  : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64                                                                                                                            5/12

  Verifying  : 1:nginx-1.12.2-2.el7.x86_64                                                                                                                                           6/12

  Verifying  : 1:nginx-mod-mail-1.12.2-2.el7.x86_64                                                                                                                                  7/12

  Verifying  : 1:nginx-all-modules-1.12.2-2.el7.noarch                                                                                                                               8/12

  Verifying  : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64                                                                                                                      9/12

  Verifying  : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64                                                                                                                    10/12

  Verifying  : 2:libunwind-1.2-2.el7.x86_64                                                                                                                                         11/12

  Verifying  : 1:nginx-mod-stream-1.12.2-2.el7.x86_64                                                                                                                               12/12

Installed:

  nginx.x86_64 1:1.12.2-2.el7                                                                                                                                                             

Dependency Installed:

  gperftools-libs.x86_64 0:2.4-8.el7               libunwind.x86_64 2:1.2-2.el7               libxslt.x86_64 0:1.1.28-5.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           

Complete!

然后去看看:

[root@xxx-general-01 robotDemo]# nginx

nginx          nginx-upgrade  

[root@xx-general-01 robotDemo]# nginx –help

nginx: invalid option: "-"

[root@xx-general-01 robotDemo]# which nginx

/usr/sbin/nginx

[root@xx-general-01 robotDemo]# nginx –version

nginx: invalid option: "-"

[root@xx-general-01 robotDemo]# nginx -h

nginx version: nginx/1.12.2

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@xx-general-01 robotDemo]# nginx -v

nginx version: nginx/1.12.2

[root@xx-general-01 robotDemo]# nginx -V

nginx version: nginx/1.12.2

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)

built with OpenSSL 1.0.2k-fips  26 Jan 2017

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_auth_request_module –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_geoip_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-mail=dynamic –with-mail_ssl_module –with-pcre –with-pcre-jit –with-stream=dynamic –with-stream_ssl_module –with-google_perftools_module –with-debug –with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong –param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ –with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’

配置文件:

[root@xx-general-01 robotDemo]# ll /etc/nginx/*

-rw-r–r– 1 root root 1077 Mar  6 17:27 /etc/nginx/fastcgi.conf

-rw-r–r– 1 root root 1077 Mar  6 17:27 /etc/nginx/fastcgi.conf.default

-rw-r–r– 1 root root 1007 Mar  6 17:27 /etc/nginx/fastcgi_params

-rw-r–r– 1 root root 1007 Mar  6 17:27 /etc/nginx/fastcgi_params.default

-rw-r–r– 1 root root 2837 Mar  6 17:27 /etc/nginx/koi-utf

-rw-r–r– 1 root root 2223 Mar  6 17:27 /etc/nginx/koi-win

-rw-r–r– 1 root root 3957 Mar  6 17:27 /etc/nginx/mime.types

-rw-r–r– 1 root root 3957 Mar  6 17:27 /etc/nginx/mime.types.default

-rw-r–r– 1 root root 2467 Mar  6 17:27 /etc/nginx/nginx.conf

-rw-r–r– 1 root root 2656 Mar  6 17:27 /etc/nginx/nginx.conf.default

-rw-r–r– 1 root root  636 Mar  6 17:27 /etc/nginx/scgi_params

-rw-r–r– 1 root root  636 Mar  6 17:27 /etc/nginx/scgi_params.default

-rw-r–r– 1 root root  664 Mar  6 17:27 /etc/nginx/uwsgi_params

-rw-r–r– 1 root root  664 Mar  6 17:27 /etc/nginx/uwsgi_params.default

-rw-r–r– 1 root root 3610 Mar  6 17:27 /etc/nginx/win-utf

/etc/nginx/conf.d:

total 0

/etc/nginx/default.d:

total 0

去启动:

[root@xx-general-01 robotDemo]# 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)

May 02 10:12:59 xx-general-01 systemd[1]: Unit nginx.service cannot be reloaded because it is inactive.

[root@xx-general-01 robotDemo]# systemctl start nginx

[root@xx-general-01 robotDemo]# 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 2018-05-02 10:15:18 CST; 1s ago

  Process: 17712 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)

  Process: 17709 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)

  Process: 17707 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Main PID: 17714 (nginx)

   CGroup: /system.slice/nginx.service

           ├─17714 nginx: master process /usr/sbin/nginx

           ├─17715 nginx: worker process

           ├─17716 nginx: worker process

           ├─17717 nginx: worker process

           └─17718 nginx: worker process

May 02 10:15:18 xx-general-01 systemd[1]: Starting The nginx HTTP and reverse proxy server…

May 02 10:15:18 xx-general-01 nginx[17709]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

May 02 10:15:18 xx-general-01 nginx[17709]: nginx: configuration file /etc/nginx/nginx.conf test is successful

May 02 10:15:18 xx-general-01 systemd[1]: Started The nginx HTTP and reverse proxy server.

然后就可以看到默认nginx页面了:

http://x.x.x.109/

设置开机启动:

[root@xx-general-01 robotDemo]# systemctl enable nginx

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

[root@xx-general-01 robotDemo]# systemctl is-enabled nginx  

enabled

测试语法是对的:

[root@xx-general-01 robotDemo]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

CentOS 7 yum 安装 Nginx – CSDN博客

“Nginx配置信息

网站文件存放默认目录

/usr/share/nginx/html

网站默认站点配置

/etc/nginx/conf.d/default.conf

自定义Nginx站点配置文件存放目录

/etc/nginx/conf.d/

Nginx全局配置

/etc/nginx/nginx.conf

Nginx启动

nginx -c nginx.conf"

【总结】

此处CentOS 7.4中,安装nginx,直接用yum去安装:

yum -y install nginx

查看nginx版本:

nginx -h

此处是:nginx/1.12.2

查看配置文件所在目录:

ls -lha /etc/nginx/*

然后启动:

systemctl status nginx

查看状态:

systemctl status nginx

设置开机启动:

systemctl enable nginx

查看是否已设置为开机启动:

systemctl is-enabled nginx

转载请注明:在路上 » 【已解决】CentOS 7中安装Nginx

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.798 seconds, using 22.23MB memory