美文网首页
Linux日记本_05:Nginx搭建

Linux日记本_05:Nginx搭建

作者: Mr_Elliot | 来源:发表于2018-10-29 18:38 被阅读0次
nginx 安装成功

1.Nginx安装环境

gcc 安装

安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++

安装 gcc

PCRE

PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。

安装pcre

zlib

zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel

安装zlib

openssl

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel

安装openssl

2.编译安装

将Nginx 安装包上传到服务器
解压:
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0

下面将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录

./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/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
make install

configure
编译
make install
启动Nginx
./nginx
然后直接访问ip试试看
停止Nginx
./nginx -s quit

3.Nginx配置文件的修改

找到conf 中的 nginx.conf 文件
编辑文件
vim nginx.conf
键入 i 进行文字插入

nginx.conf

改完之后重启Nginx,然后查看响应头中的信息,发现tomcat已经被Nginx代理


响应头中的nginx代理

相关文章

网友评论

      本文标题:Linux日记本_05:Nginx搭建

      本文链接:https://www.haomeiwen.com/subject/btfitqtx.html