Centos下编译安装nginx

申明

当前文章使用的 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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值