南京市英语网站建设,凡科自助建站平台,app制作软件教程,教资注册网址亲测有效#xff1b;
转#xff1a; https://segmentfault.com/a/1190000007116797https://segmentfault.com/a/1190000007116797
nginx服务器详细安装过程#xff08;使用yum 和 源码包两种安装方式#xff0c;并说明其区别#xff09;
正在上传…重新上传取消fuyi…亲测有效
转 https://segmentfault.com/a/1190000007116797https://segmentfault.com/a/1190000007116797
nginx服务器详细安装过程使用yum 和 源码包两种安装方式并说明其区别
正在上传…重新上传取消fuyi501发布于 2016-10-10 网上看别人写的 nginx 服务器配置 有的是源码包安装的有的时 yum 安装的。如果是新手可能会有疑问这两种安装方式有什么区别我应该使用哪种方式系统里可以两个都安装可以吗怎么卸载等等问题那么在这里我做下总结详细介绍下这两种方式。 yum 和 源码包 安装的 区别
这里先说明下 yum 和 源码包 安装的 区别
yum 安装是在线安装好处是安装方式简单不易出错源码包 安装是先将 nginx 的源码下载下来在自己的系统里编译生成可执行文件然后执行好处是因为是在自己的系统上编译的更符合自己系统的性能也就是说在自己的系统上执行 nginx 服务性能效率更好。
安装路径不同
他们之间最大的区别是 安装位置不同。
yum 在线安装会将 nginx 的安装文件放在系统的不同位置可以通过命令 rpm -ql nginx 来查看安装路径如下所示
➜ ~ rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/ssl.conf
/etc/nginx/conf.d/virtual.conf
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params.default
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/mime.types.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
/etc/nginx/scgi_params
/etc/nginx/scgi_params.default
/etc/nginx/uwsgi_params
/etc/nginx/uwsgi_params.default
/etc/nginx/win-utf
/etc/rc.d/init.d/nginx
/etc/sysconfig/nginx
/usr/lib/perl5/vendor_perl/auto/nginx
/usr/lib/perl5/vendor_perl/auto/nginx/nginx.so
/usr/lib/perl5/vendor_perl/nginx.pm
/usr/sbin/nginx
/usr/share/doc/nginx-1.0.15
/usr/share/doc/nginx-1.0.15/CHANGES
/usr/share/doc/nginx-1.0.15/LICENSE
/usr/share/doc/nginx-1.0.15/README
/usr/share/man/man3/nginx.3pm.gz
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx/html/404.html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/usr/share/nginx/html/nginx-logo.png
/usr/share/nginx/html/poweredby.png
/usr/share/vim/vimfiles/ftdetect/nginx.vim
/usr/share/vim/vimfiles/indent/nginx.vim
/usr/share/vim/vimfiles/syntax/nginx.vim
/var/lib/nginx
/var/lib/nginx/tmp
/var/log/nginx
卸载的时候只能通过 命令来卸载因为我们不可能 将这些文件自己手动删除可以通过命令 rpm -e nginx 来卸载这个命令一般不会报错因为 nginx 不与其他的包有依赖关系如果提示关于 依赖包的问题 可以尝试 rpm -e --nodeps nginx 来卸载这个命令相当于强制卸载不考虑依赖问题。
源码包 安装他的所有文件包括配置文件库文件资源文件等都在同一个目录下我们想卸载的时候直接将这个文件删除就可以不会有任何垃圾文件存在。 通过源码包编译安装的软件通常都放在 /usr/local/包名 路径下。
启动方式不同
yum 安装 nginx我们可以通过 系统服务命令 service 来启动或停止
service nginx start #启动 nginx 服务service nginx stop #停止 nginx 服务service nginx restart #重启 nginx 服务源码包 安装 nginx 启动的时候不能使用 service 来启动需要执行 nginx 安装目录下的 sbin 目录下的 nginx 可执行程序才行如下我的 nginx 安装在 /usr/local/webserver/ 目录下
➜ ~ /usr/local/webserver/nginx/sbin/nginx #启动 nginx 服务
➜ ~ /usr/local/webserver/nginx/sbin/nginx -s stop #停止 nginx 服务
或者 直接进入安装目录 执行 ./nginx 也可以这两种方式其实是一样的. 表示当前目录
➜ ~ cd /usr/local/webserver/nginx/sbin
➜ sbin ls
nginx
➜ sbin ./nginx #启动 nginx 服务
➜ sbin ./nginx -s stop #停止 nginx 服务
注意在自己的系统中只用选择一种安装方式即可yum 安装的 nginx 版本可能不是最新的可以通过 源码包 安装最新的但系统中只要一种就可以如果你想安装两个安装也可以但是他们监听的端口都是 80 端口每次只能启动一个
好先讲了区别下面来看一下安装方式
yum 安装 nginx
安装
使用 yum 安装是在线安装直接使用命令 yum -y install nginx 安装即可
➜ ~ yum -y install nginx
已加载插件fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
解决依赖关系
-- 执行事务检查
--- Package nginx.i686 0:1.0.15-12.el6 will be 安装
-- 完成依赖关系计算依赖关系解决软件包 架构 版本 仓库 大小正在安装:nginx i686 1.0.15-12.el6 epel 410 k事务概要Install 1 Package(s)总下载量410 k
Installed size: 1.1 M
下载软件包
nginx-1.0.15-12.el6.i686.rpm | 410 kB 00:00
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.正在安装 : nginx-1.0.15-12.el6.i686 1/1 Verifying : nginx-1.0.15-12.el6.i686 1/1 已安装:nginx.i686 0:1.0.15-12.el6 完毕
到这里就安装完成了是不是很简单。
启动 nginx 服务
➜ ~ service nginx start
Starting nginx: [ OK ]
停止 nginx 服务
➜ ~ service nginx stop
Stopping nginx: [ OK ]
重启 nginx 服务
➜ ~ service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
启动后 在浏览器中 输入服务器的 ip 地址就可以看到 到这里 yum 安装 nginx 就完成了 源码包 安装 nginx亲测有效
安装编译
我的系统 centos 6.7 32位首先安装缺少的依赖包
yum -y install gcc gcc-c make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
从 http://nginx.org/en/download.... 下载稳定版 nginx-1.10.1.tar.gz 下载的压缩文件 放在任意地方都可以但是建议放在 /usr/local/src 或者 /root/ 下/usr/local/src 就是系统专门给用户分配的放 源码的目录/root/ 是我们默认操作的目录所以也可以放在这里。我就是下载放在 /root/ 目录下的。
下载可以通过命令获取
wget http://nginx.org/download/nginx-1.10.1.tar.gz解压缩
tar -zxvf nginx-1.10.1.tar.gz解压缩后可以看到 nginx-1.10.1 目录然后进入这个目录
➜ ~ ls
anaconda-ks.cfg install.log install.log.syslog nginx-1.10.1 nginx-1.10.1.tar.gz
➜ ~ cd nginx-1.10.1
在 nginx-1.10.1 目录下执行 配置 和 make 命令
➜ nginx-1.10.1 ./configure --prefix/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre➜ nginx-1.10.1 make make install
常用编译选项说明
这段说明参考自https://segmentfault.com/a/11... --prefixPATH 指定 nginx 的安装目录。默认 /usr/local/nginx我的是 /usr/local/webserver/nginx --conf-pathPATH 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动通过命令行中的-c选项。默认为conf/nginx.conf --username 设置nginx工作进程的用户。安装完成后可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。--groupname类似 --with-pcre 设置PCRE库的源码路径如果已通过yum方式安装使用--with-pcre自动找到库文件。使用--with-pcrePATH时需要从PCRE网站下载pcre库的源码8.39并解压指定 pcre 的源码路径 比如--with-pcre/root/pcre-8.39/。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。 --with-zlibPATH 指定 zlib版本1.1.3 - 1.2.5的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。 --with-http_ssl_module 使用https协议模块。默认情况下该模块没有被构建。前提是openssl与openssl-devel已安装 --with-http_stub_status_module 用来监控 Nginx 的当前状态 --with-http_realip_module 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For)意义在于能够使得后台服务器记录原始客户端的IP地址 --add-modulePATH 添加第三方外部模块如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译Tengine可以在新加入module时无需重新编译
启动 停止 nginx
使用 源码包 安装 nginx 启动时需要使用绝对路径来执行如下
➜ ~ /usr/local/webserver/nginx/sbin/nginx #启动 nginx 服务
➜ ~ /usr/local/webserver/nginx/sbin/nginx -s stop #停止 nginx 服务
启动 nginx 服务后可以通过 ps -aux | grep nginx 查看进程
➜ ~ /usr/local/webserver/nginx/sbin/nginx #启动 nginx 服务
➜ ~ ps -aux | grep nginx
Warning: bad syntax, perhaps a bogus -? See /usr/share/doc/procps-3.2.8/FAQ
root 9628 0.0 0.1 15292 1500 ? Ss 11:17 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 9631 0.0 0.2 15448 2312 ? S 11:17 0:00 nginx: worker process
root 13158 0.0 0.0 6048 788 pts/1 S 12:12 0:00 grep --colorauto --exclude-dir.bzr --exclude-dirCVS --exclude-dir.git --exclude-dir.hg --exclude-dir.svn nginx
启动后 在浏览器中 输入服务器的 ip 地址就可以看到 到这里 源码包 安装 nginx 就完成了
可以看出 两个欢迎页面是不同的这个主要是版本不同的原因。
结语 这里讲了 使用 yum 和 源码包 安装 nginx 的详细过程如果想了解 yum 和 源码包 安装软件的其他详细知识可以看我的另外一篇博文 《Linux 软件安装管理》。 本文中如有纰漏或者你有什么问题都可以提出来谢谢