linux 安装 nginx 启用服务(屈折)

如果不清楚机器上是否已经安装了NGINX,使用WHICH NGINX命令查看是否存在

查看NGINX安装目录命令

WHEREIS NGINX

如果已经安装了NGINX、卸载命令为

sudo apt-get --purge remove nginx

NGINX 需要伪静态模块PCRE库,如果没安装就装上,不然NGINX安装不了。下载路径也许已经失效了,请使用迅雷下载。

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz
tar zxvf pcre-8.12.tar.gz
./configure
make
sudo make install

 

NGINX官方下载路径 http://nginx.org/download/ 当前最新稳定版本为1.4.3。

开始安装........

wget http://nginx.org/download/nginx-1.4.3.tar.gz

获取文件目录然后解压 tar zxvf nginx-1.4.3.tar.gz

cd nginx-1.4.3
./configure
 --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module
make
sudo make install

先执行./configure 看看有没有错误。如果有错误请问百度,

 

nginx算是安装好了、不过还不能用、进入nginix目录、一般来说./configure不指定目录安装的话是安装在/usr/local/nginx、如果迩想指定其它目录用上--prefix=xxx目录、如果迩是安装在默认目录的话、执行个软链接命令把nginx连去/usr/bin目录下、

sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx

 注意啦、root权限、相信也没多大问题了、然后在哪里都可以运行nginx了、执行一下nginx -v如果看到版本号就算是安装完成了

NGINX我们需要以服务启动,按下面的步骤即可实现。

vi /etc/init.d/nginx
然后输入下面的代码
你也可以通过WGET命令下载
:wq
如果你是通过WGET下载请使用 cp nginx /etc/init.d/ 复制过去

chmod
+x /etc/init.d/nginx 修改权限
chkconfig
--add nginx 添加为服务
chkconfig nginx on 服务设置为启用
serivce nginx start
HTTP://127.0.0.1/
到这里如果顺利,恭喜你已经成功安装NGINX。

 

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid

RETVAL=0
prog="nginx"

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x $nginxd ] || exit 0


# Start nginx daemons functions.
start() {

if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi

   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL

}


# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}


# reload nginx service functions.
reload() {

    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo

}

# See how we were called.
case "$1" in
start)
        start
        ;;

stop)
        stop
        ;;

reload)
        reload
        ;;

restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac

exit $RETVAL

 

如果你运行service nginx start提示

env: /etc/init.d/nginx: No such file or directory

这是因为文件格式不适合LINUX,解决办法我们使用dos2unix命令转换一次。

cd /etc/init.d/
dos2unix nginx
serivce nginx start

 

 

 

 

 

posted on 2013-11-06 22:33  shuan1626  阅读(315)  评论(0)    收藏  举报

导航