nginx安装配置步骤

​ yum install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel -y

[root@nginx1 apps]# cd /opt/
[root@nginx1 apps]# mkdir apps
[root@nginx1 apps]# cd apps/
将nginx压缩包上传到本路径下
解压:
[root@nginx1 apps]# tar -zxvf nginx-1.16.1.tar.gz
[root@nginx1 apps]# cd nginx-1.16.1/
[root@nginx1 nginx-1.16.1]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@nginx1 nginx-1.16.1]#

auto: 存放nginx自动安装的相关文件

conf:存放nginx服务器配置文件

configure:命令,用于对即将安装的软件的配置,完成makefile编译文件的生成

contrib:存放由其他机构贡献的文档材料

html:存放nginx欢迎界面

man:manual,手册,存放nginx帮助文档

src:存放nginx源码

​ 在nginx解压目录下运行make命令,用于完成编译。但此时会给出提示:没有指定目标,并且没有发现编译文件makefile.编译命令make需要根据编译文件makefile进行编译,所以在编译之前需要先生成编译文件makefile.使用configure命令可以生成该文件。那么,configure命令需要配置哪些参数呢?使用–help可以查看到可以使用的参数说明。这些参数可以分为三类:

第一类:基本信息的配置

第二类:默认没有安装,可以指定安装的模块,使用–with开头。nginx的高拓展性就体现在这里

第三类:默认已经安装,可以指定卸载的模块,使用–without开头

​ 下面是简单配置的命令执行。命令中每一行的最后添加了反斜杠\表示当前命令并未结束,回车不会执行该命令。执行成功护,会给出配置报告。下面以安装对https访问协议支持的模块http_ssl_module为例。

​ –prefix:用于指定nginx的安装目录。注意,安装目录与解压目录不一样。

​ –http_ssl_module:https访问协议需要安装http安全连接协议模块SSL(Secure SocketsLayer,安全套接层)。注意,在执行过configure命令后并不会立即生成/usr/local/nginx目录,也不会马上开始安装指定的模块,而仅仅是将命令中指定的参数及默认配置写道即将要生成的makefile文件中。

配置报告以两部分构成:第一部分给出了配置的系统库;第二部分给出了系统配置信息。

​ path prefix: 指定nginx安装目录

​ binary file: nginx命令文件

​ modules path: nginx模块存放路径

​ configuration prefix: nginx配置文件存放路径

​ onfiguraion file: nginx配置文件名

​ pid file: nginx的进程id文件

​ error log file:错误日志文件

​ http access log file: http访问日志文件

​ http xxx: 其他http请求相关的文件。

配置成功后,再次查看nginx解压目录,发现其中多出了一个文件makefile。后面的编译就是依靠该文件进行的。

[root@nginx1 nginx-1.16.1]# mkdir -p /var/tmp/nginx/client
[root@nginx1 nginx-1.16.1]# pwd
/opt/apps/nginx-1.16.1
[root@nginx1 nginx-1.16.1]# ./configure \
> prefix=/opt/nginx \
> sbin-path=/usr/sbin/nginx \
> conf-path=/etc/nginx/nginx.conf \
> error-log-path=/var/log/nginx/error.log \
> http-log-path=/var/log/nginx/access.log \
> pit-path=/var/run/nginx/nginx.pid \
> lock-path=/var/lock/nginx.lock \
> user=nginx \
> group=nginx \
> with-http_ssl_module \
> with-http_flv_module \
> with-http_stub_status_module \
> with-http_gzip_static_module \
> http-client-body-temp-path=/var/tmp/nginx/client/ \
> http-prxy-temp-path=/var/tmp/nginx/proxy/ \
> http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
> http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
> http-scgi-temp-path=/var/tmp/nginx/scgi \
> with-pcre
注意:/var/tmp/nginx/client目录需要手动创建

也可以使用简单安装,指定安装目录和https访问支持

[root@nginx1 nginx-1.16.1]# pwd
/opt/apps/nginx-1.16.1
[root@nginx1 nginx-1.16.1]# ./configure \
> prefix=//nginx \
> with-http_ssl_module \
> with-http_gzip_static_module \
> error-log-path=/var/log/nginx/nginx.log \
> pid-path=/var/log/nginx.pid
[root@nginx1 nginx-1.16.1]# pwd
/opt/apps/nginx-1.16.1
[root@nginx1 nginx-1.16.1]# ./configure
checking for OS
 + Linux 3.10.0-1160.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-44) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
....

nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
[root@nginx1 nginx-1.16.1]#

这是两个命令,make为编译命令,make install 为安装命令,可以分别执行。这里使用&&将这两个命令连接执行,会在前面命令执行成功的前提下才会执行第二个命令。

[root@nginx1 nginx-1.16.1]# pwd
/opt/apps/nginx-1.16.1
[root@nginx1 nginx-1.16.1]# make && make install
https://blog.csdn.net/qq_36194413/article/details/85841097

在nginx的安装目录/opt/nginx中有一个sbin目录,其中存放着nginx的命令程序nginx。默认情况下,若要使用nginx命令,则必须要在/opt/nginx/sbin目录中,或指定命令路径,使用起来很不方便。为了能够在任意目录下均可直接执行nginx命令。

[root@nginx ~]# vi /usr/lib/systemd/system/nginx.service

输入如下内容:

[Unit]
Description=nginx - High performance web server, proxy server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/log/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[root@nginx /]# systemctl enable nginx.service
[root@nginx /]# systemctl restart nginx.service

基本操作示例:

\1. 启动服务

​ systemctl start nginx.service

\2. 重启服务

​ systemctl restart nginx.service

\3. 重载服务

​ systemctl reload nginx.service

\4. 停止服务

​ systemctl stop nginx.service

[root@nginx /]# ln -s  /opt/nginx/sbin/nginx /usr/local/sbin/nginx
[root@nginx /]# vi ~/.bash_profile
在export PATH 后面添加nginx命令的路径,例如PATH=$HADOOP_PREFIX/bin:$PATH:$HOME/bin:$SPARK_HOME/bin:/opt/nginx/sbin/nginx
[root@nginx1 ~]#systemctl service nginx start
Starting nginx (via systemctl):  Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

[root@nginx1 ~]# systemctl status nginx.service
● nginx.service - SYSV: Nginx is an HTTP(S) server,HTTP(S) reverse
   Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since 二 2021-09-28 08:02:35 CST; 42s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1369 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)

9月 28 08:02:35 nginx1 systemd[1]: Starting SYSV: Nginx is an HTTP(S) server,HTTP(S) reverse...

9月 28 08:02:35 nginx1 nginx[1369]: /etc/rc.d/init.d/nginx:行20: ${basename $nginx}: 坏的替换
9月 28 08:02:35 nginx1 systemd[1]: nginx.service: control process exited, code=exited status=1
9月 28 08:02:35 nginx1 systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server,HTTP(S) reverse.

9月 28 08:02:35 nginx1 systemd[1]: Unit nginx.service entered failed state.

9月 28 08:02:35 nginx1 systemd[1]: nginx.service failed.

Original: https://www.cnblogs.com/Boyka1/p/15366196.html
Author: 程胥员
Title: nginx安装配置步骤

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/598520/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • cobbler

    cobbler 1. cobbler简介 2. cobbler服务端部署 cobbler简介 Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速…

    Linux 2023年6月7日
    081
  • php+apache环境搭建

    【先安装apache】 1、安装基础环境: yum -y install gcc libxml2 libxml2-devel sqlite-devel libcurl-devel….

    Linux 2023年6月6日
    082
  • 国产化之x64平台安装银河麒麟操作系统

    背景 某个项目需要实现基础软件全部国产化,其中操作系统指定银河麒麟v4,CPU使用飞腾处理器。飞腾处理器是ARMv8架构的,在之前的文章中介绍了使用QEMU模拟ARMv8架构安装银…

    Linux 2023年5月27日
    085
  • 【总结】瞬时高并发(秒杀/活动)Redis方案

    1,Redis 丰富的数据结构(Data Structures) * 字符串(String) – Redis字符串能包含 任意类型的数据 一个字符串类型的值最多能存储 …

    Linux 2023年5月28日
    086
  • docker学习笔记—基本命令

    1、docker start/stop/restart/kill 启动/停止/重启/杀掉容器 实例操作如下: 2、docker run 创建并启动一个新的容器 常用参数如下: 实例…

    Linux 2023年6月8日
    0105
  • Docker 搭建 Nexus3 私服 | 基本操作

    1 Docker 安装 Nexus3 1.1 创建目录 在硬盘上创建 Nexus3 的主目录: mkdir -p /Users/yygnb/dockerMe/nexus3 为该目录…

    Linux 2023年6月7日
    082
  • mysql字符串拼接

    Mysql数据库中的字符串 CONCAT()CONCAT_WS()GROUP_CONCAT() CONCAT() CONCAT(string1,string2)最常用的字符串拼接方…

    Linux 2023年6月6日
    077
  • 高通平台如何避免误入FFBM模式

    前面两篇博客分别介绍了通过fastboot和QFIL工具退出FFBM模式的方法。虽然售后的同学可以这么指导用户做恢复,但步骤多操作也麻烦,且属于事后处理,如果大面积高概率地出现,会…

    Linux 2023年6月7日
    0102
  • CentOS7.6下Oracle19C RAC集群詳細搭建步驟

    CentOS7.6搭建RAC 1.系统环境配置 1.1概述 ​ 搭建两个节点的rac集群,其每个节点均有两个网卡,public网卡和private网卡。两个节点的主机名分别为rac…

    Linux 2023年6月13日
    074
  • Java轻松实现,每天给对象发情话!

    一、引言 最近看到一篇用js代码实现表白的文章,深有感触。然后发现自己也可以用java代码实现,然后就开始写代码了,发现还挺有意思的,话不多说开搞实现思路: 使用HttpClien…

    Linux 2023年6月14日
    086
  • (十)redis源码解读

    一、redis工作机制 redis是 单线程,所有命令(set,get等)都会加入到队列中,然后一个个执行。 二、为什么redis速度快? 1、基于内存 2、redis协议resp…

    Linux 2023年5月28日
    0110
  • cache和内存屏障

    1 cache简介 1.1 cache缓存映射规则 tag查看cache是否匹配,set index |tag |set index |block offset ||20-bit …

    Linux 2023年6月6日
    0109
  • 好玩的免费GM游戏整理汇总

    前言 我所有架设的游戏发布和更新都会实时整理到本文 https://echeverra.cn/h5game , 建议收藏。 游戏全部 免费带 GM后台(可以免费充值发送游戏道具),…

    Linux 2023年6月7日
    0105
  • 高通MSM8998 ABL的调试

    高通在MSM8998上引入了UEFI,用来代替LK(Little Kernel)。高通UEFI由XBL和ABL两部分组成。XBL负责芯片驱动及充电等核心应用功能。ABL包括芯片无关…

    Linux 2023年6月7日
    085
  • 【Leetcode】300. 最长递增子序列

    给你一个整数数组 nums,找到其中最长严格递增子序列的长度。 子序列是由数组派生而来的序列,删除(或不删除)数组…

    Linux 2023年6月6日
    0123
  • Kafka 配置文件详情

    kafka的配置分为 broker、producter、consumer三个不同的配置 一 、BROKER 的全局配置 最为核心的三个配置 broker.id、log.dir、zo…

    Linux 2023年6月8日
    089
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球