大佬教程收集整理的这篇文章主要介绍了centos 7下安装配置nginx,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。
一. gcc 安装
安装 Nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yuminstallgcc-c++
二. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。Nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。Nginx也需要此库。命令:
yuminstall-ypcrepcre-devel
三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, Nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
yuminstall-yzlibzlib-devel
四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
Nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
yuminstall-yopensslopenssl-devel
1.直接下载.tar.gz
安装包,地址:https://nginx.org/en/download.html
s.width=650;" src="http://img.code.cc/vcimg/static/loading.png" http://code.js-code.com/tag/nginx/"="" target="_blank" class="keywords">
2.使用wget
命令下载(推荐)。
wget-chttps://Nginx.org/download/Nginx-1.10.1.tar.gz
s.width=650;" src="http://img.code.cc/vcimg/static/loading.png" http://code.js-code.com/tag/nginx/"="" target="_blank" class="keywords">
我下载的是1.10.1版本,这个是目前的稳定版。
依然是直接命令:
tar-zxvfNginx-1.10.1.tar.gzcdNginx-1.10.1
其实在 Nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.自定义配置(最好定义自己的配置路径)
./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
查找安装路径:
whereisNginx
s.width=650;" src="http://img.code.cc/vcimg/static/loading.png" http://code.js-code.com/tag/nginx/"="" target="_blank" class="keywords">
cd/usr/local/Nginx/sbin/ 注意这里会报错,如下: Nginx:[emerg]mkdir()"/var/temp/Nginx/proxy"Failed(2:NosuchfiLeordirectory) 原因是我们使用了临时的目录,仅需自己重新创建一个新的目录即可: mkdir/var/temp/Nginx/client-pv 接下来就可以成功启动了 ./Nginx启动 在本机通过localhost无法访问linux上的ngnix 修改ngnix.conf上的 ./Nginx-sstop ./Nginx-squit ./Nginx-sreload
psaux|grepNginx
1.先停止再启动(推荐):
对 Nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./Nginx-squit ./Nginx
2.重新加载配置文件:
当 ngin x的配置文件 Nginx.conf 修改后,要想让配置生效需要重启 Nginx,使用-s reload
不用先停止 ngin x再启动 Nginx 即可将配置信息在 Nginx 中生效,如下:
./Nginx -s reload
启动成功后,在浏览器可以看到这样的页面:
本机访问地址:192.168.1.11:8013
s.width=650;" src="http://img.code.cc/vcimg/static/loading.png" http://code.js-code.com/tag/nginx/"="" target="_blank" class="keywords">
以上是大佬教程为你收集整理的centos 7下安装配置nginx全部内容,希望文章能够帮你解决centos 7下安装配置nginx所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。