CentOS 7 安装Nginx 并配置自动启动
1、官网下载安装包
http://nginx.org/en/download.html,选择适合Linux的版本,这里选择最新的版本,下载到本地后上传到服务器或者centos下直接wget命令下载。

切换到/usr/local目录,下载软件包
|
1
2
|
# cd /usr/local# wget http://nginx.org/download/nginx-1.11.5.tar.gz |
2、安装nginx
先执行以下命令,安装nginx依赖库,如果缺少依赖库,可能会安装失败,具体可以参考文章后面的错误提示信息。
|
1
2
3
4
5
6
7
|
# yum install gcc-c++# yum install pcre# yum install pcre-devel# yum install zlib # yum install zlib-devel# yum install openssl# yum install openssl-devel |
解压安装包
|
1
|
# tar -zxvf nginx-1.11.5.tar.gz |
nginx被解压到了/usr/local/nginx-1.11.5 目录下(不要把压缩包解压到/usr/local/nginx目录下,或者将解压后的目录重命名为nginx,因为nginx会默认安装到/usr/local/nginx目录下),切换到nginx-1.11.5/目录
|
1
|
# cd /usr/local/nginx-1.11.5/ |
执行# ./configure
|
1
|
# ./configure |
该操作会检测当前系统环境,以确保能成功安装nginx,执行该操作后可能会出现以下几种提示:
checking for OS
+ Linux 3.10.0-123.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
如果出现以上错误提示信息,执行yum install gcc-c++安装gcc,
./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.
如果出现上面提示,表示缺少PCRE库
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
如果出现以上提示,表示缺少zlib库
如果没有出现./configure: error提示,表示当前环境可以安装nginx,执行make和make install编译nginx
|
1
2
|
# make# make install |
没有出错的话,表示nginx已经成功安装完成,默认安装位置为/usr/local/nginx,之前的/usr/local/nginx-1.11.5/可以删除掉了。
如果出现cp: 'conf/koi-win' and '/usr/local/nginx/conf/koi-win' are the same file,可能是你把安装包解压到了/usr/local/nginx目录,解决办法是将该目录重命名为其他名称后再执行make,make install.
3、配置nginx开机启动
切换到/lib/systemd/system/目录,创建nginx.service文件vim nginx.service
|
1
2
|
# cd /lib/systemd/system/# vim nginx.service |
文件内容如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[Unit]Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx reloadExecStop=/usr/local/nginx/sbin/nginx quitPrivateTmp=true [Install] WantedBy=multi-user.target |
退出并保存文件,执行systemctl enable nginx.service使nginx开机启动
|
1
|
# systemctl enable nginx.service |
systemctl start nginx.service 启动nginx
systemctl stop nginx.service 结束nginx
systemctl restart nginx.service 重启nginx
4、验证是否安装成功
输入http://服务器IP/ 如果能看到nginx的界面,就表示安装成功了
CentOS 7 安装Nginx 并配置自动启动的更多相关文章
- CentOS 下 安装 nginx 执行配置命令 ./configure 报错
CentOS 下 安装 nginx 执行配置命令 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx 时提示以下错误: checkin ...
- Ubuntu编译安装nginx以及配置自动启动
本文主要介绍ubuntu如何编译安装nginx以及遇到的问题 和 配置系统自动启动服务 查看操作系统版本 cat /etc/issue Ubuntu 18.04.3 LTS \n \l 更改镜 ...
- CentOS 7 安装 Nginx 配置反向代理
Linux使用Nginx Yum存储库上安装Nginx,适用于Red Hat Enterprise Linux和CentOS系统. 1.添加设置Nginx Yum存储库 在CentOS中首次安装Ngi ...
- CentOS 7安装nginx
CentOS 7安装nginx 参考网上其他文章做的 安装Nginx 我们从nginx官方的RPM源来安装一个预构建的稳定版本的nginx包. rpm --import http://nginx.or ...
- 【转】linux 编译安装nginx,配置自启动脚本
linux 编译安装nginx,配置自启动脚本 本文章来给各位同学介绍一篇关于linux 编译安装nginx,配置自启动脚本教程,希望有需要了解的朋友可一起来学习学习哦. 在公司的suse服务器装ng ...
- CentOS 6.6 nginx PHP 配置
/************************************************************************* * CentOS 6.6 nginx PHP 配置 ...
- linux 编译安装nginx,配置自启动脚本
本文章来给各位同学介绍一篇关于linux 编译安装nginx,配置自启动脚本教程,希望有需要了解的朋友可一起来学习学习哦. 在公司的suse服务器装nginx,记录下安装过程: 参照这篇文章:Linu ...
- 删:Centos 7安装Nginx 1.8
[CentOS 7] 安装nginx! 首先进行 nginx yum Nginx安装记录 注意:如果用源码安装,nginx配置时需要指定--with-pcer对应的压缩包路径,如果使用二进制安装不需要 ...
- linux/centos下安装nginx(rpm安装和源码安装)详细步骤
Centos下安装nginx rpm包 ...
随机推荐
- jQuery 滑动选项卡SmartTab
Smart Tab Overview Smart Tab is a jQuery plugin for tabbed interface. It is flexible and very easy t ...
- Content-type与json对象/字符串杂谈
这几天在对接项目另一个乙方的下行接口,因为最近一直用php开发,所以当那边接口文档上规定了接口传参类型的 时候,瞬间搞混了,但是这次的出错也让我对http的数据传输有了新的认知. 1.http的数据传 ...
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB3' for column 'Content' at row 1
在尝试将 emoji 表情符号 插入MySQL数据库时,遇到以下错误信息: ### The error occurred while setting parameters ### SQL: INSER ...
- PHPStorm 添加支持 PSR-4 命名空间前缀设置
许久没有更新博客啦, 太忙了, 七月这最后一天来写点自己在使用 PHPStorm 上的小却很有用的功能吧. PHPStorm 默认是使用 PSR-0 命名空间规范的, 前提是你需要标记好项目中的源码根 ...
- swift metal ios8 关键字.
swift metal ios8 关键字. 4000API. 无所谓谁打败谁吧. 行业内用户用的多 资源多 问题容易解决. 今年明显unity 火热程度非常. 然,万变不离其中. 对于游戏产品来说, ...
- 解决 src/MD2.c:31:20: fatal error: Python.h: No such file or directory安装包错误
在linux命令行安装包时报错 src/MD2.c:31:20: fatal error: Python.h: No such file or directory 原因:缺少了python的dev 解 ...
- learn go anonymous function
package main // 参考文档: // https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/06.8.md im ...
- 【剑指offer】二叉树的子结构,C++实现(递归)
原创博文,转载请注明出处! <牛客链接> 1.题目 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:约定空树不是任意一个树的子结构) 图1.二叉树A和二叉树B 2.思路(递归) ...
- VS 工具箱 Dev控件显示
工具箱修复Dev控件显示 用VS2010新打开一个项目,居然发现工具箱里边没了Dev控件. 命令提示符定位到Dev控件的安装目录下的\Components\Tools文件夹下,执行如下命令 添加:To ...
- librec库
固定初始化矩阵值 net.librec.math.structure -> class DenseMatrix -> void init()