发布于 2015-12-04 05:24:05 | 152 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的Nginx中文文档,程序狗速度看过来!

Nginx WEB服务器

Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。


申明

当前文章使用的 Nginx 版本: 1.4.4 stable 下载

.bz2 解压命令 $ tar jxf file-name

.gz 解压命令 $ tar zxf file-name

推荐事先安装的一些依赖

$ yum install -y gcc gcc-c++ make cmake autoconf libtool \
libtool-ltdl-devel pcre pcre-devel gd-devel freetype-devel \
libxml2-devel libjpeg-devel libpng-devel openssl-devel \
curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel \
sudo bzip2 bzip2-devel bison perl-devel perl-ExtUtils-Embed \
libcurl-devel libjpeg-devel libpng-devel freetype-devel \
t1lib-devel libicu-devel mhash libmcrypt libmcrypt libiconv \
libxslt-devel openldap-devel

 
添加用户组

$ groupadd nginx
$ useradd -g nginx -s /sbin/nologin nginx

新建日志目录

$ mkdir -p /var/nginx/log

编译安装Nginx

编译参数

$ ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/usr/local/etc/nginx/nginx.conf \
--error-log-path=/var/nginx/log/nginx/error.log \
--http-log-path=/var/nginx/log/nginx/access.log \
--pid-path=/var/nginx/log/run/nginx.pid \
--lock-path=/var/nginx/log/lock/subsys/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_gzip_static_module \
--with-http_stub_status_module \
--with-http_perl_module \
--with-mail \
--with-mail_ssl_module > out

安装

$ make
$ make install

注意事项

1.如果碰到

./configure: error: the HTTP rewrite module requires the PCRE library.,请安装pcre-devel:

$ yum -y install pcre-devel

2.如果使用—with-http_sub_module参数编译出错的话,加参数—with-openssl=/download/openssl-1.0.1c, 这里指定的openssl目录是源码包解压出来的目录而不是openssl的安装目录。

配置文件

新建虚拟主机配置文件

$ vim /usr/local/etc/nginx/vhost.conf

加入

server {
    listen 80;
    server_name foo.com;

    root /www/foo;
    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        try_files $uri = 404;

        include fastcgi.conf;
        fastcgi_pass 127.0.0.1:9000;
    }
}

在ningx.conf里引入虚拟主机配置文件

$ vim /usr/local/etc/nginx/nginx.conf

修改如下

http {
    include       mime.types;
    include       vhosts.conf;   // 引入虚拟主机配置文件
    default_type  application/octet-stream;

Nginx命令

启动

$ nginx

平滑重启

$ nginx -s reload

停止

$ nginx -s stop


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务