当前位置: > CentOS > CentOS教程 >

CentOS_7.2安装Nginx_1.9

时间:2016-10-08 21:12来源:linux.it.net.cn 作者:IT

一、安装依赖包和开发工具:

yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf python-devel zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* libicu-devel libxslt-devel postgresql-devel curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33

二、清除系统中的httpd痕迹

yum remove httpd
rm -rvf /etc/httpd
rm /usr/bin/pod2man

三、创建www用户和用户组:

groupadd www
useradd -s /sbin/nologin -g www www

四、解压nginx模块包:

tar zxvf zlib-1.2.8.tar.gz -C /usr/src
tar zxvf pcre-8.12.tar.gz -C /usr/src
tar zxvf openssl-1.0.1.tar.gz -C /usr/src

五、解压、配置、编译、安装nginx_1.9:

tar zxvf nginx-1.9.0.tar.gz -C /usr/src/
cd /usr/src/nginx-1.9.0/
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/home/www/log/error.log \
--http-log-path=/home/www/log/access.log \
--pid-path=/home/www/pid/nginx.pid \
--lock-path=/home/www/pid/nginx.lock \
--with-mail \
--with-file-aio \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_sub_module \
--with-http_spdy_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-zlib=/usr/src/zlib-1.2.8 \
--with-pcre=/usr/src/pcre-8.12 \
--with-openssl=/usr/src/openssl-1.0.1 \
--without-select_module \
--without-poll_module \
--http-client-body-temp-path=/tmp/clientbody \
--http-proxy-temp-path=/tmp/proxy \
--http-fastcgi-temp-path=/tmp/fastcgi \
--http-uwsgi-temp-path=/tmp/uwsgi \
--http-scgi-temp-path=/tmp/scgi
make
make install

六、编辑nginx.conf配置文件:

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx.conf
vim /etc/nginx.conf
 View Code

七、创建nginx相关目录,并修改权限:

mkdir -p /home/www/html
chown -R www:www /home/www/

八、测试启动nginx服务:

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
nginx -t
nginx -c /usr/local/nginx/conf/nginx.conf
ps -aux | grep nginx
netstat -anptu | grep 80

九、编写nginx启动脚本:

vim /etc/init.d/nginx
 View Code

十、添加nginx系统服务:

chmod a+x /etc/init.d/nginx 
chkconfig --add nginx 
chkconfig --level 2345 nginx on 
chkconfig --list | grep nginx

十一、重新启动nginx服务:

service nginx restart
ps -aux | grep nginx
netstat -anptu | grep 80

十二、测试:

vim /home/www/html/index.html
 View Code
chown www:www /home/www/html/index.html

 

十三、防火墙开启80端口:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT



(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容