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

nginx编译安装和基于域名的虚拟主机配置

2014-10-23 10:17 447 查看
1.CentOS5.8 x86_64位 采用最小化安装,系统经过了基本优化篇
2.nginx版本:nginx-1.4.7
3.源码包存放位置:/home/oldboy/tools
4.源码包编译安装位置:/application/

一.下载安装prce

wget http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz/download tar zxf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install
二.安装nginx
1.下载

wget http://nginx.org/download/nginx-1.4.7.tar.gz[/code]   2.安装

tar zxf nginx-1.4.7.tar.gz
cd nginx-1.4.7
useradd -s /sbin/nologin -M nginx
./configure  \
--user=nginx \
--group=nginx \
--prefix=/application/nginx-1.4.7 \
--with-http_stub_status_module \
--with-http_ssl_module
make && make install
ln -s /application/nginx-1.4.7/ /application/nginx
ll -d /application/nginx
cd /application/nginx
报错:
[root@ser200 nginx]# sbin/nginx
sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or director
[root@ser200 nginx]# find / -name libpcre*
/usr/local/lib/libpcre.so.1
[root@ser200 nginx]#vi /etc/ld.so.conf #这个文件记录了编译时使用的动态链接库的路径
include ld.so.conf.d/*.conf
/usr/local/lib
[root@ser200 nginx]# ldconfig #它的作用就是将/etc/ld.so.conf列出的路径下的库文件 缓存到/etc/ld.so.cache 以供使用

/etc/ld.so.conf 此文件记录了编译时使用的动态库的路径,也就是加载so库的路径。

默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件,而通常通过源码包进行安装时,如果不指定--prefix会将库安装在/usr/local目录下,而又没有在文件/etc/ld.so.conf中添加/usr/local/lib这个目录。这样虽然安装了源码包,但是使用时仍然找不到相关的.so库,就会报错。也就是说系统不知道安装了源码包。

对于此种情况有2种解决办法:

(1)在用源码安装时,用--prefix指定安装路径为/usr/lib。这样的话也就不用配置PKG_CONFIG_PATH

(2) 直接将路径/usr/local/lib路径加入到文件/etc/ld.so.conf文件的中。在文件/etc/ld.so.conf中末尾直接添加:/usr/local/lib(这个方法给力!)

ldconfig

再来看看ldconfig这个程序,位于/sbin下,它的作用是将文件/etc/ld.so.conf列出的路径下的库文件缓存到/etc/ld.so.cache以供使用,因此当安装完一些库文件,或者修改/etc/ld.so.conf增加了库的新的搜索路径,需要运行一下ldconfig,使所有的库文件都被缓存到文件/etc/ld.so.cache中,如果没做,可能会找不到刚安装的库

三.nginx基于域名的虚拟主机配置
1.添加运行nginx服务的用户,可以优化

[root@ser200 nginx]# useradd -s /sbin/nologin -M nginx
[root@ser200 nginx]# vi conf/nginx.conf
user nginx nginx;
2.增运nginx运行的方式
events {
use epoll;
worker_connections 1024;
}
3.设置启动时开启的进程数,依据CPU的个数进行调节
worker_processes 4;
4.增加虚拟主机
server {
listen 80;
server_name blog.test.com; #兼听的域名

location / {
root /data/www/blog; #主机目录
index index.html index.htm; #索引页面
access_log /app/logs/blog_access.log main; #访问日志名字上文对应
}
}

http段有main的日志格式设置
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

5.可以用include的方式来加载虚拟主机的配置文件
include conf/extra/nginx_vhost.conf

6.检查语法和平滑启动

[root@ser200 conf]# ../sbin/nginx -t
[root@ser200 conf]# ../sbin/nginx -s reload
[root@ser200 conf]# lsof -i :80


本文出自 “蜘蛛侠” 博客,请务必保留此出处http://txidc.blog.51cto.com/9138217/1567059
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: