linux下安装nginx

来源:互联网 发布:淘宝店铺刷收藏会抓吗 编辑:程序博客网 时间:2024/05/17 08:20


本文参考:http://luhuang.sinaapp.com/linux-nginx-rewrite/

Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。 Igor 将源代码以类 BSD 许可证的形式发布

1、为了确保能在 Nginx 中使用正则表达式进行更灵活的配置,安装之前需要确定系统是否安装有 PCRE(Perl Compatible Regular Expressions)包。您可以到ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包

Nginx的安装需要依赖于gcc、openssl-devel、pcre-devel、zlib-devel

1、先安装 openssl

yum install openssl

2、 下载 pcre 软件 Rewrite 配置的使用
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz
tar -zxvf pcre-8.32.tar.gz
cd pcre-8.32
./configure
make
make install

3、安装 zlib
wget http://zlib.net/zlib-1.2.7.tar.gz
tar -zxvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure
make
make install

4、下载 Nginx 软件

http://nginx.org/download/nginx-1.2.8.tar.gz

解压配置和安装 进入目录
./configure –prefix=/usr/local/nginx –with-pcre=pcre-8.32的源码目录
make
make install

注: –with-pcre=pcre-8.32 指的是pcre-8.32 的源码路径

我的 nginx.conf 的 server 配置:
server {
listen 80;
server_name www.**.com;
#server_name ~^(?.+).**.com
index index.php;
root /usr/local/nginx/photo;

#charset koi8-r;

rewrite ^(.*)\.html$ /index.php?domain=111 break;

location ~ \.php$ {
#root /usr/local/nginx/huanglu;
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

rewrite_log on;
error_log logs/rewrite.error.log notice;

location / {
index index.php index.html index.htm;
}
}

5、测试 Nginx 配置文件是否正确
/usr/local/nginx/sbin/nginx -t #测试配置文件是否正确

6、启动Nginx:
/usr/local/nginx/sbin/nginx

7、测试:
http://域名或IP/index.html 是否正确 如果没有达到rewrite 请查看 日志: logs/rewrite.error.log

出现如下则正确:

 

/usr/local/nginx/sbin/nginx #启动Nginx

 

如出现以下错误:

/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

解决办法如下:

在redhat 64位机器上, nginx可能读取的pcre文件为/lib64/libpcre.so.1文件.

ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1

ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1





上述是参考文章中的操作方式,本人操作平台为fedora 10 版本



安装zlib

1、在http://www.zlib.net/下载zlib的最新版

2、解压,编译:

  ./configure

   make

   sudu make install



本人配置文件为默认:

server {
        listen       80;
        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root   html;
            index  index.html index.htm;
        }

安装测试过程中,也出现了:/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory


通过 cp  /lib/libpcre.so.0.0.1  /lib/libpcre.so.1  解决


通过ie访问:http://localhost/index.html 

获取如下显示:

Welcome to nginx!


If you see this page, the nginx web server is successfully installed and working. Further configuration is required.


For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.


Thank you for using nginx.



0 0
原创粉丝点击