Nginx基础:1:安装与部署

在这里插入图片描述
使用容器方式的Nginx非常方便,但是这种方式需要Docker运行环境的支持,所以在有些情况下直接在物理机器上安装和设定Nginx的方式仍然非常方便。这篇文章进行一下相关的基础介绍。

安装命令

CentOS/RHEL安装命令: yum install nginx

注意:此安装包目前在epel-release下,所以需要先行安装epel-release。

Ubuntu安装命令: apt install nginx

安装

事前环境确认

[root@liumiaocn ~]# uname -a
Linux liumiaocn 5.4.2-1.el7.elrepo.x86_64 #1 SMP Wed Dec 4 17:32:23 EST 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@liumiaocn ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@liumiaocn ~]# 

安装

执行如下命令即可完成安装

步骤1: yum install epel-release -y

步骤2: yum install nginx -y

版本确认

[root@liumiaocn ~]# nginx -v
nginx version: nginx/1.16.1
[root@liumiaocn ~]#

启动nginx服务

启动命令: systemctl start nginx

在这里插入图片描述

配置信息确认

使用nginx -V即可确认详细的配置信息,比如本文示例的配置信息如下所示

[root@liumiaocn ~]# nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (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_ssl_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_preread_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-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@liumiaocn ~]#

从上述内容中可以看到一些配置与设定以及此nginx的模块

  • 二进制文件:/usr/sbin/nginx
  • 安装目录:/usr/share/nginx
  • 配置文件目录:/etc/nginx
  • 配置文件:/etc/nginx/nginx.conf
  • 访问日志信息:/var/log/nginx/access.log
  • 错误日志信息:/var/log/nginx/error.log
  • 模块保存目录:/usr/lib64/nginx/modules

结果确认

缺省启动后服务会在80端口启动,所以直接使用http://IP或者域名的方式即可直接访问,访问后可以看到如下内容:
在这里插入图片描述
这个原因是因为此epel-release下的index.html已经被修改了

[root@liumiaocn ~]# cd /usr/share/nginx/html/
[root@liumiaocn html]# grep 'CentOS' index.html
  <title>Welcome to CentOS</title>
	<h1>Welcome to CentOS</h1>
	<p><a href="http://www.centos.org/">CentOS</a> is an Enterprise-class Linux Distribution derived from sources freely provided
to the public by Red Hat, Inc. for Red Hat Enterprise Linux.  CentOS conforms fully with the upstream vendors
redistribution policy and aims to be functionally compatible. (CentOS mainly changes packages to remove upstream vendor
	<p>CentOS is developed by a small but growing team of core
	<p>CentOS has numerous advantages including: an active and growing user community, quickly rebuilt, tested, and QA'ed errata packages, an extensive <a href="http://www.centos.org/download/mirrors/">mirror network</a>, developers who are contactable and responsive, Special Interest Groups (<a href="http://wiki.centos.org/SpecialInterestGroup/">SIGs</a>) to add functionality to the core CentOS distribution, and multiple community support avenues including a <a href="http://wiki.centos.org/">wiki</a>, <a
[root@liumiaocn html]# 

正常出现此页面,则能说明在CentOS下的nginx的安装和启动已经正常。

发布了1021 篇原创文章 · 获赞 1288 · 访问量 398万+

猜你喜欢

转载自blog.csdn.net/liumiaocn/article/details/104104445
今日推荐