当前位置:首页 > Web开发 > 正文

nginx之旅第一篇:nginx下载安装、nginx配置文件详解、nginx默认网站

2024-03-31 Web开发

标签:

一、nginx下载安装

版本nginx 1.15.5

系统环境centos7.5(本机ip192.168.199.228)

关闭selinux 和防火墙firewall

1、下载

wget -P /usr/src

2、安装

安装大概过程

配置---编译---安装

配置 1)检查环境 是否 满足安装条件 依赖解决 2)指定安装方式 配置文件 命令文件 各种文件放哪里 开启模块功能【内 置模块 三方模块】 3)指定软件安装在那里

a、切换到usr/src目录,解压文件

[[email protected] src]# cd /usr/src [[email protected] src]# ls debug kernels nginx-1.15.5.tar.gz [[email protected] src]# tar xf nginx-1.15.5.tar.gz [[email protected] src]# ls debug kernels nginx-1.15.5 nginx-1.15.5.tar.gz [[email protected] src]#

  

?

查看配置方法

[[email protected] src]# pwd /usr/src [[email protected] src]# cd nginx-1.15.5 [[email protected] nginx-1.15.5]# ls auto CHANGES.ru configure html man src CHANGES conf contrib LICENSE README [[email protected] nginx-1.15.5]# ./configure --help #查看配置参数帮助

  


?

b、安装各种依赖环境

[[email protected] src]# cd nginx-1.15.5 [[email protected] nginx-1.15.5]# yum -y install gcc pcre-devel zlib zlib-devel Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.vpshosting.com.hk * extras: centos.01link.hk * updates: hk.mirrors.thegigabit.com Resolving Dependencies --> Running transaction check ---> Package gcc.x86_64 0:4.8.5-39.el7 will be installed ...

  

gcc 编译工具

pcre-devel 在nginx中url 需要用到这个包

zlib zlib-devel 解压缩工具

 对于 gcc,因为安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境的话,需要安装gcc。

  对于 pcre,prce(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

  对于 zlib,zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

c、指定目录进行编译

[[email protected] nginx-1.15.5]# ./configure --prefix=http://www.mamicode.com/usr/local/nginx checking for OS + Linux 3.10.0-862.el7.x86_64 x86_64 checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ...

  

d、编译make

make就是将源码进行编译生成可执行程序的过程

[[email protected] nginx-1.15.5]# pwd /usr/src/nginx-1.15.5 [[email protected] nginx-1.15.5]# ls auto CHANGES.ru configure html Makefile objs src CHANGES conf contrib LICENSE man README [[email protected] nginx-1.15.5]# make make -f objs/Makefile make[1]: Entering directory `/usr/src/nginx-1.15.5‘ cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs ...

  

没有error的话进行

e、make install完成安装

[[email protected] nginx-1.15.5]# make install make -f objs/Makefile install make[1]: Entering directory `/usr/src/nginx-1.15.5‘ test -d ‘/usr/local/nginx‘ || mkdir -p ‘/usr/local/nginx‘ test -d ‘/usr/local/nginx/sbin‘ ...

  

完成安装

二、nginx的相关目录

nginx path prefix: "/usr/local/nginx" #nginx的安装目录 nginx binary file: "/usr/local/nginx/sbin/nginx" #nginx的启动文件 nginx modules path: "/usr/local/nginx/modules" # nginx的模块目录 nginx configuration prefix: "/usr/local/nginx/conf" #nginx的配置文件位置 nginx configuration file: "/usr/local/nginx/conf/nginx.conf" #nginx的配置文件全路径 nginx pid file: "/usr/local/nginx/logs/nginx.pid" #nginx的进程号 nginx error log file: "/usr/local/nginx/logs/error.log" #nginx的错误日志目录 nginx http access log file: "/usr/local/nginx/logs/access.log" #nginx的访问日志目录

  

三、nginx的启动与关闭、检查配置文件

查看端口是否占用

方法一

安装netstat 用netstat进行查看

[[email protected] nginx]# yum -y install net-tools Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile ... ? ? [[email protected] nginx]# netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 881/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1128/master tcp6 0 0 :::22 :::* LISTEN 881/sshd tcp6 0 0 ::1:25 :::* LISTEN 1128/master ?

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/40273.html