阿里云centos7[linux]安装nginx
2024-10-12 13:19:19
标题 | 说明 |
---|---|
服务器版本 | Centos7 x64 |
nginx版本 | 1.19.6 |
作者 | walton |
一、准备
- 创建安装包目录并进入
mkdir /usr/dev/nginx
cd /usr/dev/nginx
- 下载安装包
wget http://nginx.org/download/nginx-1.19.6.tar.gz
或者
在 http://nginx.org/download/ 直接下载对应版本安装包上传到服务器文件夹内
Q: 如何获取下载版本?
A: 在此网站中(http://nginx.org/download/)获取版本,然后修改wget命令后的版本号
- 解压安装包并进入
tar -zxvf nginx-1.19.6.tar.gz
cd /nginx-1.19.6
二、安装
- 设置安装路径(默认路径:/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
- 编译nginx
当前目录下执行make命令,该命令是将源文件编译为可执行文件
[root@fanzyx nginx-1.19.6]# make
编译成功,如图所示、
- 安装文件
将编译后的文件复制到设置的安装目录
[root@fanzyx nginx-1.19.6]# make install
三、相关命令
- 启动
为nginx指定配置文件路径并启动
[root@fanzyx nginx-1.19.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- 停止
方法一:
[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]#
- 重启
安装路径 -s reload
/usr/local/nginx/sbin/nginx -s reload
- 查看配置是否正确
安装路径 -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]#
最新文章
- iOS:交换Button中图片与文字的左右位置
- Got a packet bigger than &#39;max_allowed_packet&#39; bytes
- java通过ftp和sftp上传war包上传到Linux服务器实现自动重启tomcat的脚本代码
- Ubuntu上安装Maven Eclipse以及配置
- ubuntu13.04云主机部署gitlab6.6
- linux 服务自动调用
- Keil: warning: A1581W: Added 2 bytes of padding at address
- &;lt;Android&;gt;从窗口泄漏谈android:configChanges属性
- 专题一、ArrayList增删操作技术细节详解
- TCP/IP具体解释--三次握手和四次握手 Dos攻击
- JS学习之事件冒泡
- iOS 开发 Message Digest Algorithm 5(MD5加密)
- 基于visual Studio2013解决面试题之0208二叉搜索树后序遍历序列
- 源代码编译安装 PHP5.5.0,解决curl_exec訪问HTTPS返回502错误的问题
- 用EnableMenuItem不能使菜单变灰的原因
- adb模拟操作之event
- N-Queens(N皇后问题)
- java基础-String不可变的好处
- Linux硬盘文件分析取证(SSH过的IP)
- CSS 实现自动换行、强制换行、强制不换行的属性