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)

大家都在看

  • 重载规则

    1、可重载的运算符 + – * / % ^ & | ~ ! = < > += -= *= /= %= ^= &= |= << >&gt…

    Linux 2023年6月13日
    082
  • ruoyi接口权限校验

    此文章属于ruoyi项目实战系列 ruoyi系统在前端主要通过权限字符包含与否来动态显示目录和按钮。为了防止通过http请求绕过权限限制,后端接口也需要进行相关权限设计。 @Pre…

    Linux 2023年6月7日
    0138
  • Linux中CentOS 7的安装及Linux常用命令

    前言 什么是Linux Linux是一套免费使用和自由传播的操作系统。说到操作系统,大家比较熟知的应该就是Windows和MacOS操作系统,我们今天所学习的Linux也是一款操作…

    Linux 2023年6月6日
    0127
  • MySQL之多表查询、Navicat及pymysql

    一、多表查询 1.1 数据准备 — 建表 create table dep( id int primary key auto_increment, name varchar(20…

    Linux 2023年6月14日
    097
  • 【Docker搭建】2. 在Docker中安装Redis5.0

    1. 安装Docker,详细 请看安装教程 。若已安装,请看 2. 2. 拉取 Redis 镜像 docker pull redis:5.0.5 3. 设置 Redis 配置文件 …

    Linux 2023年6月13日
    079
  • 【微服务】- 服务调用-OpenFeign

    服务调用 – OpenFeign 😄生命不息,写作不止🔥 继续踏上学习之路,学之分享笔记👊 总有一天我也能像各位大佬一样🏆 一个有梦有戏的人 @怒放吧德德🌝分享学习心得…

    Linux 2023年6月6日
    083
  • Linux、Windows下Redis的安装即Redis的基本使用详解

    前言 什么是Redis Redis是一个基于 内存的key-value结构数据库。Redis 是互联网技术领域使用最为广泛的存储中间件,它是「 Remote Dictionary …

    Linux 2023年6月6日
    0108
  • Unity编译时找不到AndroidSDK的问题 | Unable to list target platforms(转载)

    现象 在用 Unity 编译 Android 平台的应用时,遇到 Unable to list target platforms 的问题。 错误提示 详细错误描述如下: Error…

    Linux 2023年6月7日
    0106
  • zabbix自定义监控进程与日志

    zabbix自定义监控进程与日志 zabbix自定义监控进程与日志 zabbix自定义监控进程 zabbix自定义监控日志 zabbix自定义监控进程 现在我们需要监控客户端的某一…

    Linux 2023年6月13日
    0112
  • jenkins集成gitlab 授权登录

    配置方法:1.gitlab 新建个人application 如上图, Name, 名称随便填 Redirect URI: http://xxxxxx/securityRealm/f…

    Linux 2023年6月14日
    0152
  • 【学习笔记】13.5 使用者的特殊 shell 与 PAM 模块

    我们前面一直谈到的大多是一般身份使用者与系统管理员 (root) 的相关操作, 而且大多是讨论关于可登陆系统的帐号来说。那么换个角度想,如果我今天想要创建的, 是一个”…

    Linux 2023年5月28日
    083
  • Docker安装使用及私有仓库搭建

    1 概念 1.1 基本概念 Docker daemon​ 守护进程,运行在宿主机上,用户通过DockerClient客户端Docker命令与Docker daemon交互。Dock…

    Linux 2023年5月27日
    087
  • 剑指offer计划19( 搜索与回溯算法中等)—java

    1.1、题目1 剑指 Offer 64. 求1+2+…+n 1.2、解法 这题看评论区真的绝了,都是人才,各个说话都好听,我看到个还有用异常来结束的就离谱。这题用了&a…

    Linux 2023年6月11日
    081
  • redis主从复制

    Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。 特性: 运行在内存中的数据集工作方式 支持多种数据结构 提供不同级别的磁盘持…

    Linux 2023年5月28日
    070
  • Linux 进程卡住了怎么办?

    在我们使用 Linux 系统时,如果网络或者磁盘等 I/O 出问题,会发现进程卡住了,即使用 kill -9 也无法杀掉进程,很多常用的调试工具,比如 strace, pstack…

    Linux 2023年5月27日
    073
  • ASP.NET Core 发布到Linux需要注意的地方

    ☆☆☆ 共同学习,欢迎拍砖;转载请注明出处,谢谢。欢迎关注我的公众号:闲聊编程。☆☆☆ Original: https://www.cnblogs.com/FlyLolo/p/11…

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