标签:nginx编译安装
(1)下载nginx
[root@LNMP ~]# cd /usr/local/src/
[root@LNMP src]# wget http://nginx.org/download/nginx-1.4.4.tar.gz
(2)解压Nginx
[root@LNMP src]# tar zxvf nginx-1.4.4.tar.gz
(3)配置编译参数
[root@LNMP src]# cd nginx-1.4.4
[root@LNMP nginx-1.4.4]#./configure --prefix=/usr/local/nginx --with-pcre
(4)编译、安装Nginx
[root@LNMP nginx-1.4.4]# make
[root@LNMP nginx-1.4.4]# make install
因为nginx比较小,所以很快就会安装完,而且也不会出什么错误。
(5)编写nginx启动脚本,并加入系统服务
[root@LNMP nginx-1.4.4]# vim /etc/init.d/nginx
写入如下内容:
#!/bin/bash # chkconfig: - 30 21 # description: http service. # Source Function Library . /etc/init.d/functions # Nginx Settings NGINX_SBIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" RETVAL=0 prog="Nginx" start() { echo -n $"Starting $prog: " mkdir -p /dev/shm/nginx_temp daemon $NGINX_SBIN -c $NGINX_CONF RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p $NGINX_PID $NGINX_SBIN -TERM rm -rf /dev/shm/nginx_temp RETVAL=$? echo return $RETVAL } reload(){ echo -n $"Reloading $prog: " killproc -p $NGINX_PID $NGINX_SBIN -HUP RETVAL=$? echo return $RETVAL } restart(){ stop start } configtest(){ $NGINX_SBIN -c $NGINX_CONF -t return 0 } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; configtest) configtest ;; *) echo $"Usage: $0 {start|stop|reload|restart|configtest}" RETVAL=1 esac exit $RETVAL
保存后,更改权限:
[root@LNMP nginx-1.4.4]# chmod 755 /etc/init.d/nginx
[root@LNMP nginx-1.4.4]# chkconfig --add nginx
开机启动,请执行:
[root@LNMP nginx-1.4.4]# chkconfig nginx on
(6)更改nginx配置
首先把原来的配置文件清空:
[root@LNMP nginx-1.4.4]# > /usr/local/nginx/conf/nginx.conf
“>” 这个符号之前介绍过,为重定向的意思,单独用它,可以把一个文本文档快速清空。
[root@LNMP nginx-1.4.4]# vim /usr/local/nginx/conf/nginx.conf
在配置文件中找到以下内容,去掉内容前面的#,并改正红色部分
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
保存配置后,先检验一下配置文件是否有错误存在:
[root@LNMP nginx-1.4.4]# /usr/local/nginx/sbin/nginx -t
如果显示内容如下,则配置正确,否则需要根据错误提示修改配置文件:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
(7)启动nginx:
[root@LNMP nginx-1.4.4]# service nginx start
如果不能启动,请查看 “/usr/local/nginx/logs/error.log” 文件,检查nginx是否启动:
[root@LNMP nginx-1.4.4]# ps aux |grep nginx
root 8208 0.0 0.0 5364 636 ? Ss Apr01 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 8209 0.0 0.1 6544 2036 ? S Apr01 0:00 nginx: worker process
nobody 8210 0.0 0.1 6544 1952 ? S Apr01 0:00 nginx: worker process
root 8212 0.0 0.0 5980 748 pts/0 S+ 00:00 0:00 grep nginx
本文出自 “12350027” 博客,谢绝转载!
标签:nginx编译安装
原文地址:http://12360027.blog.51cto.com/12350027/1936765