您的位置:首页 > 运维架构 > Nginx

关于编译的yum安装nginx出现404页面原因

2012-10-16 00:14 459 查看
在现今网络如此普及的环境下,大多数人会选择采用yum安装各种服务,配置简单,启动简单……

但是因此也带来了很多不便的方面,此篇就讲述这样一件不便的操作;

我作为一个刚接触运维不久的新人,之所以发表是为了表示对老大的敬佩和感激……在此对我的老大们表示感谢,也为自己加把油!

环境为cetos6.2

已更新了yum源

rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/epel-release-6-5.noarch.rpm

rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/ius-release-1.0-10.ius.el6.noarch.rpm rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
yum install -y nginx-release-centos.noarch nginx
但是在使用中,我们往往需要用到源码nginx的集成模块,所以会采用源码包方式编译,添加相应的模块:
下载源码nginx 看自己的需求http://nginx.org/en/download.html
然后tar zxvf nginx-1.3.7.tar.gz
cd nginx-1.3.7
./configure --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-cc-opt='-O2 -g' --add-module=./src/nginx-http-concat --add-module=./src/ngx_devel_kit --add-module=./src/lua-module
make && make install
%注意编译需要的nginx模块,注意路径为yum默认安装的目录,可以通过./configure --help进行查看
以上便是yum安装的nginx添加编译模块的方法

nginx模块增加了,自然服务得心应手,但是相应的问题也就出现了,最近我们家网站出现了一些莫名其妙的404页面,我自知没有那个耐心和细心去发现问题,但经过老大的研究,原来如此,下面就给大家讲一讲:
为什么在这里谈起呢,接着上面添加编译的部分写呢?嘿嘿,首先再次感谢我的老大们的教诲,小弟一定加倍努力;主要是这个错误竟然是因为上面添加编译模块导致的;下面就让小弟给大家说一下,因为自己的理解也有限,讲不明白的地方,希望各位别见怪:
在老大查看原因的时候,日志里会出现了很多 [error] 9427#0: *6099 open() "/etc/nginx/html/50x.html" failed (2: No such file or directory)
先看看nginx定义的页面信息
error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}
这是定义的nginx本目录,即/etc/nginx
ls /etc/nginx/html/ 确实没有这个目录,由此可知那些莫名其妙的404页面,原来是因为找不到定义的50x页面引起的,那为什么会没有这个目录呢?那让我们看一看yum安装的nginx目录结构
# rpm -qa | grep nginx

nginx-release-centos-6-0.el6.ngx.noarch

nginx-1.2.3-1.el6.ngx.x86_64
# rpm -ql nginx-1.2.3-1.el6.ngx.x86_64

/etc/logrotate.d/nginx

/etc/nginx

/etc/nginx/conf.d

/etc/nginx/conf.d/default.conf

/etc/nginx/conf.d/example_ssl.conf

/etc/nginx/fastcgi_params

/etc/nginx/koi-utf

/etc/nginx/koi-win

/etc/nginx/mime.types

/etc/nginx/nginx.conf

/etc/nginx/scgi_params

/etc/nginx/uwsgi_params

/etc/nginx/win-utf

/etc/rc.d/init.d/nginx

/etc/sysconfig/nginx

/usr/sbin/nginx

/usr/share/nginx

/usr/share/nginx/html ---------------注意

/usr/share/nginx/html/50x.html --------这两行

/usr/share/nginx/html/index.html

/var/cache/nginx

/var/log/nginx
yum安装的nginx会默认将html目录安装在/usr/share下,那为什么会找不到呢,
ls /usr/share/nginx/html 啊,真的有50x.html,那为什么会去/etc/nginx/html的目录呢?
这中间可能造成这个错误的原因有两个,要么是认为的删除了,但是这几乎是不可能的,我们的权限很严格,不可能如此简单的删除的,那剩下的就是编译模块出错了,那是什么错呢?
#tar zxvf nginx-1.3.7.tar.gz
#cd nginx-1.3.7
#find . -name 50x.html
./html/50x.html 还真有,那让我们来看看这里面有什么
#grep 'html' -r *

auto/install:if test -d html ; then

auto/install: NGX_HTML=html

auto/install: NGX_HTML=docs/html

auto/install: test -d '\$(DESTDIR)$NGX_PREFIX/html' \
嗯,这是什么呢?来看看
#vim auto/install
里面东西还真不少,这里就不全写出来了,只让大家看看这里面的一句话:

test -d '\$(DESTDIR)$NGX_PREFIX/html' \

|| cp -R $NGX_HTML '\$(DESTDIR)$NGX_PREFIX'
是说将html这个目录拷贝到编译目录下,这里编译的目录是/etc/nginx/
这下开朗了,那解决方法有两种
1.将/usr/share/nginx/html 拷贝到/etc/nginx 下;
2.修改配置文件定义的page路径
error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

以上看似不是大问题,但真的是不耐心研究的话真不容易找到原因,老大的这份心态值得大家学习。。。。
最后祝大家工作顺利。

本文出自 “Luffy的梦” 博客,请务必保留此出处http://huoyingdk.blog.51cto.com/3932829/1027172
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐