Centos 7.5安装 Nginx 1.14.1
1. 准备工作
查看系统版本
输入命令
cat /etc/redhat-release
我的Centos版本
CentOS Linux release 7.5.1804 (Core)
安装nginx所需的依赖
gcc安装
安装 nginx 需要先将官网下载的源码进行编译,而编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yum install -y gcc-c++
PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:
yum install -y pcre pcre-devel
zlib 安装
zlib 库提供了很多种压缩和解压缩的方式 nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库
yum install -y zlib zlib-devel
OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。yum install -y openssl openssl-devel
2. 下载nginx
下载地址:
选择稳定版本

3. 上传
使用xshell连接linux系统 再使用xftp上传文件到指定目录
我的目录
/app/tool/
4. 解压
解压到当前目录
tar zxf nginx-1.14.1.tar.gz
目录结构

5. 初始化nginx(配置)
解压完成后进入解压目录
cd /app/tool/nginx-1.14.1
配置
其实在 nginx-1.14.0 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。默认配置(推荐)
编译
./configure
完成输出的结果

自定义配置
注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
6. 编译安装
执行
make && make install
输出结果最后一行:
make[1]: Leaving directory `/app/tool/nginx-1.14.1'
查找安装路径
whereis nginx
输出结果:
nginx: /usr/local/nginx
7. 启动与重启
启动
进入sbin目录
cd /usr/local/nginx/sbin
启动
./nginx
停止
先查出nginx进程id再使用kill命令强制杀掉进程
./nginx -s stop
停止:等待nginx进程处理任务完毕进行停止
./nginx -s quit
重启
先停止再启动
./nginx -s quit
./nginx重载配置文件
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
8. 反向代理
编辑配置文件
修改/usr/local/nginx/conf下的 nginx.conf文件
vim /usr/local/nginx/conf/nginx.conf
修改配置文件
在nginx.conf的http{}里面添加
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
9. 配置https
检查模块
进入/usr/local/nginx/sbin/目录下 查看nginx版本与编译安装了哪些模块
cd /usr/local/nginx/sbin/
./nginx -V
添加http_ssl_module模块
进入nginx解压目录下配置nginx
cd /app/tool/nginx-1.14.1/
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
编译
千万不要make install 否则会覆盖现有的nginx
make
关闭nginx
进入/usr/local/nginx/sbin/目录下./nginx -s quit
复制配置目录
将/app/tool/nginx-1.14.1/objs/nginx 替换/usr/local/nginx/sbin/nginx
复制前注意先将之前的nginx文件备份
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
复制 如果提示是否覆盖 键入y即可
cp /app/tool/nginx-1.14.1/objs/nginx /usr/local/nginx/sbin/
查看编译安装的模块
进入/usr/local/nginx/sbin/目录下
cd /usr/local/nginx/sbin/
./nginx -V
上传证书
我上传的目录为
/usr/local/nginx/conf
我使用的是腾讯云的免费证书
将1_域名_bundle.crt和2_域名.key上传到 /usr/local/nginx/conf/目录下修改nginx.conf
vim /usr/local/nginx/conf/nginx.conf
在
http{}末尾添加以下内容注:example.com应换成自己的域名
server {
listen 80;
server_name example.com;
send_timeout 1800; rewrite ^(.*) https://example.com$1 permanent;
} server {
listen 443;
server_name example.com; #填写绑定证书的域名
index index.html index.htm index.php default.html default.htm default.php;
ssl on;
ssl_certificate /usr/local/nginx/conf/1_example.com_bundle.crt;
ssl_certificate_key /usr/local/nginx/conf/2_example.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
#按照这个套件配置
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
验证配置是否正确
进入/usr/local/nginx/sbin/目录下
cd /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
开启443端口
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
- 启动nginx
./nginx
现在就可以使用https访问了
10. 配置图片服务器
修改/usr/local/nginx/conf/nginx.conf
vim conf/nginx.conf
修改的位置为server{}里面,配置了https的需要在443端口server下添加如下内容,如果没有配置https则在默认80端口下添加即可
内容
location /images/ {
root /app/home/;
autoindex on;
}
修改图片目录的权限
我的目录为/app/home/
chmod 777 -R /app/home/
存放图片需要存入设置目录的images目录下
我的图片路径为
/app/home/images/
重载nginx配置文件
cd /usr/local/nginx/sbin/
./sbin -s reload访问
现在就可以访问图片了,访问地址为域名(iP:端口)/images/图片名称.后缀
Centos 7.5安装 Nginx 1.14.1的更多相关文章
- CentOS 7.4安装Nginx 1.14.0
一.安装所需环境 1.gcc 安装 yum install gcc-c++
- 编译安装 nginx -1.14.2
编译安装 nginx -1.14.2 1 ) 下载nginx-1.14.2 源码包: wget http://nginx.org/download/nginx-1.14.2.tar.gz 2 ) 编译 ...
- 在CentOS 7中安装nginx服务器
简要地介绍一下,如何在CentOS 7中安装nginx服务器 下载对应当前系统版本的nginx包(package) # wget http://nginx.org/packages/centos/ ...
- Python之——CentOS 6.5安装Python2.7.14
Python之——CentOS 6.5安装Python2.7.14 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/l1028386804/art ...
- Linux系统运维笔记(四),CentOS 6.4安装Nginx
Linux系统运维笔记(四),CentOS 6.4安装Nginx 1,安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool op ...
- 如何在 CentOS 7 上安装 Nginx
本文首发:开发指南:如何在 CentOS 7 上安装 Nginx Nginx 读作 engine x, 是一个免费的.开源的.高性能的 HTTP 和反向代理服务,主要负责负载一些访问量比较大的站点. ...
- CentOS 7 源代码安装Nginx
本篇简要介绍CentOS 7 源代码安装Nginx. Preface # yum install epel-release -y # yum group install "Developme ...
- Centos 7下安装nginx,使用yum install nginx,提示没有可用的软件包
Centos 7下安装nginx,使用yum install nginx,提示没有可用的软件包. 18 (flaskApi) [root@67 flaskDemo]# yum -y install n ...
- centos 下yum 安装nginx
centos 下yum 安装nginx 1. 直接yum install nginx不行,要先处理下源: rpm -ivh http://nginx.org/packages/centos/6/noa ...
随机推荐
- MUI - 引导页制作
引导页制作 本文的引导页和[官方的引导页示例](https://github.com/dcloudio/mui/blob/master/examples/hello-mui/examples/guid ...
- C++四:继承与派生
C++四:继承与派生 一.概念 继承就是从先辈处得到属性和行为特性.类的继承,是指新的类从已有类的那里得到的特性.类的派生,就是指已有类产生新类的过程. 二.应用 定义为 class 派生类名: ...
- react-cli
更新日志: v1.2.0 ...未完待续 v1.1.0 添加editorconfig 配置ESLint 集成prettier 集成 lint-staged 实现细节: 添加editorconfig e ...
- oracle函数 VARIANCE([distinct|all]x)
[功能]统计数据表选中行x列的方差. [参数]all表示对所有的值求方差,distinct只对不同的值求方差,默认为all 如果有参数distinct或all,需有空格与x(列)隔开. [参数]x,只 ...
- SDUT-1479_数据结构实验之栈与队列九:行编辑器
数据结构实验之栈与队列九:行编辑器 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 一个简单的行编辑程序的功能是:接受用 ...
- 05Dockerfile简介
Dockerfile是一个用于构建Docker镜像的文本文件,其中包含了创建Docker镜像的全部指令.基于这些指令,可以使用"docker build"命令来创建镜像. 一:用 ...
- Redis源码解析:06整数集合
整数集合(intset)是集合键的底层实现之一,当一个集合只包含整数值元素,并且这个集合的元素数量不多时,Redis就会使用整数集合作为集合键的底层实现. intset可以保存类型为int16_t,i ...
- mysql数据库之工作流程
MySQL架构总共四层,在上图中以虚线作为划分. 首先,最上层的服务并不是MySQL独有的,大多数给予网络的客户端/服务器的工具或者服务都有类似的架构.比如:连接处理.授权认证.安全等. 第二层的架构 ...
- 当pip安装因为网络超时而无法安装的时候慢
2.4 尝试pip --default-timeout=1000 install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp36-cp ...
- 【小程序案例】支付宝小程序-MQTT模器,IoT设备通过WSS接入阿里云IoT物联网平台
支付宝小程序-MQTT模拟器通过WSS接入阿里云IoT物联网平台 小程序效果: 1. 准备工作 1.1 注册阿里云账号 开通阿里云账号,并通过支付宝实名认证 https://www.aliyun.co ...
