Nginx安装和运行
自己安装时参考的资料,均来自网上
Nginx安装和运行
Nginx安装和运行
官方网站
一、依赖的程序
1. gzip module requires zlib library
2. rewrite module requires pcre library
3. ssl support requires openssl library
二、安装
./configure
make
make install
默认安装的路径是/usr/local/nginx
更多的安装配置
./configure --prefix=/usr/local/nginx
--with-openssl=/usr/include (启用ssl)
--with-pcre=/usr/include/pcre/ (启用正规表达式)
--with-http_stub_status_module (安装可以查看nginx状态的程序)
--with-http_memcached_module (启用memcache缓存)
--with-http_rewrite_module (启用支持url重写)
启动Nginx:
出错。。。。。。。
Nginx启动出错 error while loading shared libraries:
在centos5.7 32位上编译安照 nginx-1.1.16 出错
[root@localhost conf]# /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
从错误看出是缺少lib文件导致,进一步查看下
[root@localhost conf]# ldd $(which /usr/local/nginx/sbin/nginx)
linux-gate.so.1 => (0x0071b000)
libpthread.so.0 => /lib/libpthread.so.0 (0×00498000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0×00986000)
libpcre.so.1 => not found
libcrypto.so.6 => /lib/libcrypto.so.6 (0×00196000)
libz.so.1 => /lib/libz.so.1 (0×00610000)
libc.so.6 => /lib/libc.so.6 (0x002d7000)
/lib/ld-linux.so.2 (0x006a8000)
libdl.so.2 => /lib/libdl.so.2 (0x008c3000)
可以看出 libpcre.so.1 => not found 并没有找到,进入/lib目录中手动链接下
[root@localhost lib]# ln -s libpcre.so.0.0.1 libpcre.so.1
然后在启动nginx ok 了
[root@localhost lib]# /usr/local/nginx/sbin/nginx
[root@localhost lib]# ps -ef |grep nginx
root 9539 1 0 19:06 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www 9540 9539 0 19:06 ? 00:00:00 nginx: worker process
Nginx启动出错 error while loading shared libraries:
2012年04月19日 星期四 15:43
编译安装时,添加上pcre的路径就行了
--with-pcre=../pcre-8.30
Nginx默认配置文件和默认端口
◆ /usr/local/nginx/conf/ – Nginx服务器配置目录,/usr/local/nginx/conf/nginx.conf 是主配置文件
◆ /usr/local/nginx/html/ – 默认文档位置
◆ /usr/local/nginx/logs/ – 默认日志文件位置
◆ Nginx HTTP默认端口:TCP 80
◆ Nginx HTTPS默认端口:TCP 443
可以使用下面的命令测试Nginx的配置是否正确:
# /usr/local/nginx/sbin/nginx –t
输出示例:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf test is successful
要让修改后的配置生效,执行下面的命令:
# /usr/local/nginx/sbin/nginx -s reload
如果要停止服务器,运行:
# /usr/local/nginx/sbin/nginx -s stop
最后使用webbench进行测试
webbench -c 500 -t 30 http://localhost/a.html