标题 说明
服务器版本 Centos7 x64
nginx版本 1.19.6
作者 walton

一、准备

  1. 创建安装包目录并进入
mkdir /usr/dev/nginx

cd /usr/dev/nginx
  1. 下载安装包
wget http://nginx.org/download/nginx-1.19.6.tar.gz

或者

在 http://nginx.org/download/ 直接下载对应版本安装包上传到服务器文件夹内

Q: 如何获取下载版本?

A: 在此网站中(http://nginx.org/download/)获取版本,然后修改wget命令后的版本号

  1. 解压安装包并进入
tar -zxvf nginx-1.19.6.tar.gz

cd /nginx-1.19.6

二、安装

  1. 设置安装路径(默认路径:/usr/local/nginx)
[root@fanzyx nginx-1.19.6]#  ./configure --prefix=/usr/local/nginx

出现如下错误

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

需要安装openssl,执行以下命令

[root@fanzyx nginx-1.19.6]# yum -y install openssl openssl-devel

再次执行命令
[root@fanzyx nginx-1.19.6]# ./configure --prefix=/usr/local/nginx

  1. 编译nginx
当前目录下执行make命令,该命令是将源文件编译为可执行文件

[root@fanzyx nginx-1.19.6]# make

编译成功,如图所示、

  1. 安装文件

将编译后的文件复制到设置的安装目录

[root@fanzyx nginx-1.19.6]# make install

三、相关命令

  1. 启动

为nginx指定配置文件路径并启动

[root@fanzyx nginx-1.19.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  1. 停止
方法一:
[root@fanzyx nginx-1.19.6]# /usr/local/nginx/sbin/nginx -s stop
方法二:
查询nginx进程
ps -ef | grep nginx
[root@fanzyx nginx-1.19.6]# ps -ef | grep nginx
root 15038 1 0 11:44 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 15039 15038 0 11:44 ? 00:00:00 nginx: worker process
root 15084 9881 0 11:45 pts/0 00:00:00 grep --color=auto nginx 在进程列表中带master的进程就是主进程 kill -QUIT 主进程号
eg: kill -QUIT 15038 再次执行查询命令发现主进程已消失 [root@fanzyx nginx-1.19.6]# kill -QUIT 15038
[root@fanzyx nginx-1.19.6]# ps -ef | grep nginx
root 15271 9881 0 11:50 pts/0 00:00:00 grep --color=auto nginx
[root@fanzyx nginx-1.19.6]#

  1. 重启
安装路径 -s reload

/usr/local/nginx/sbin/nginx -s reload
  1. 查看配置是否正确
安装路径 -t

/usr/local/nginx/sbin/nginx -t

如下所示配置成功
[root@fanzyx nginx-1.19.6]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@fanzyx nginx-1.19.6]#

最新文章

  1. iOS:交换Button中图片与文字的左右位置
  2. Got a packet bigger than &#39;max_allowed_packet&#39; bytes
  3. java通过ftp和sftp上传war包上传到Linux服务器实现自动重启tomcat的脚本代码
  4. Ubuntu上安装Maven Eclipse以及配置
  5. ubuntu13.04云主机部署gitlab6.6
  6. linux 服务自动调用
  7. Keil: warning: A1581W: Added 2 bytes of padding at address
  8. &amp;lt;Android&amp;gt;从窗口泄漏谈android:configChanges属性
  9. 专题一、ArrayList增删操作技术细节详解
  10. TCP/IP具体解释--三次握手和四次握手 Dos攻击
  11. JS学习之事件冒泡
  12. iOS 开发 Message Digest Algorithm 5(MD5加密)
  13. 基于visual Studio2013解决面试题之0208二叉搜索树后序遍历序列
  14. 源代码编译安装 PHP5.5.0,解决curl_exec訪问HTTPS返回502错误的问题
  15. 用EnableMenuItem不能使菜单变灰的原因
  16. adb模拟操作之event
  17. N-Queens(N皇后问题)
  18. java基础-String不可变的好处
  19. Linux硬盘文件分析取证(SSH过的IP)
  20. CSS 实现自动换行、强制换行、强制不换行的属性

热门文章

  1. SpringBoot之自定义拦截器
  2. AT2688 [ARC080C] Young Maids
  3. 题解-CF429C Guess the Tree
  4. sort by背后使用了什么排序算法
  5. centos 7 配置 mysql 5.7 主从复制
  6. Consul的使用
  7. UWB硬件设计相关内容
  8. js上 六、运算符-2
  9. PHP连接数据库的方式
  10. python3全局函数解析