设为首页 收藏本站
查看: 502|回复: 0

[经验分享] nginx web容器 安装与配置

[复制链接]

尚未签到

发表于 2016-12-23 10:07:23 | 显示全部楼层 |阅读模式
1 Nginx 安装
下载地址:http://www.nginx.org/download/nginx-1.2.3.tar.gz
使用wget命令下载 # wget http://www.nginx.org/download/nginx-1.2.3.tar.gz
解压缩: # tar -zxvf nginx-1.2.3.tar.gz
设置安装目录: #./configure --prefix=/usr/local/nginx
然后系统会检查参数
我这里报了一个错:
./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 library 库,那得先安装下这玩意,要是没报错可以跳过下面的步骤:
PCRE 包 下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz
同样的,下载后解压 #tar -zxvfpcre-8.20,配置 #./configure
编译#make 安装#make install
----------------------------------------------------------------------------------------------------------
OK!接着再进行nginx的安装目录: #./configure --prefix=/usr/local/nginx
又报了一个错。
./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 library 。。缺少zlib包。。这装系统的时候省事什么也不装,装个软件真没玩没了的了。。咱继续解决这问题:
下载地址:http://zlib.net/zlib-1.2.7.tar.gz 安装完这个我的就没问题了。你们的还有没有问题我就不知道了
---------------------------------------------------------------------------------------------------------------

进入nginx 的解压目录下 。。再来次 #./configure prefix=/usr/local/nginx
这下OK了吧 ~
编译: #make
安装:#make install
没出什么别的问题的话就这样安装完成了。

2 nginx配置
#/usr/local/nginx/sbin/nginx 启动
在浏览其中打开 127.0.0.1 是否显示"welcome to nginx "; 如果是的话则已经启动成功
如果没有启动成功 使用ps aux|grep nginx 查看 以及端口 netstat -ntlp|grep 80 看80端口是否已被nginx监听了
root 4962 0.0 0.0 2816 1008 ? Ss 02:00 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 4966 0.0 0.1 2964 1128 ? S 02:00 0:00 nginx: worker process
注意,如果显示的不是红色的 部分/usr/local/nginx/sbin/nginx
而是别的,则需要使用kill 进程号 杀掉线程重新启动
设置开机启动:echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /etc/rc.local
接着咱们来看nginx主配置文件 ( conf/nginx.conf ):
worker_processes 1;
#开启的进程数
worker_connections 1024 #每个进程最大连接数
sendfile on ; #开启搞笑文件传输模式
keepalive_timeout 100; #长链接超时时间
#########################
#########基本配置##########
server{
listen 80; #设置监听端口
server_name localhost; #设置主机名
charset utf8;#设置编码

}
location/{
root html;#指定容器文件目录
indexindex.jsp index.html ; #指定默认首页
}
error_page 500 502 503 504 /50x.html; #设置错误的默认跳转页面
location = /50x.html{
root html; #指定目录
}

############虚拟主机配置############
#第一个虚拟服务器
server{
listen 80;
server_name name1;
.……
}
#第二个虚拟服务器
server{
listen 80;
server_name name2;
.……
}
#默认虚拟服务器
server{
listen 80 default;

.……
}
#####扩展#####
#阻止访问特定目录下的文件
location ~* \.(txt|doc)$ {
root html/test;
deny all;
}
#这里的意思是阻止访问 html/test/下面的以txt 或doc 结尾的文件


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-318304-1-1.html 上篇帖子: nginx配置详解(备忘篇) 下篇帖子: Nginx Web服务器(转)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表