LNMP服务器配置(Nginx)

Nginx安装

(环境:Ubuntu 14.04)

安装法一

1. nginx依赖安装

$tar -xzvf zlib-1.2.8.tar.gz
$cd zlib-1.2.8
$./configure
$make 
$sudo make install
  • rewrire模块 pcre库
    下载地址: http://www.pcre.org/ 文件:pcre-8.38.tar.gz(推荐,10.10版本make不通过)
$tar -xzvf pcre-8.38.tar.gz
$cd pcre-8.38
$./configure
$make
$sudo make install
$tar -xzvf openssl-1.0.1g.tar.gz
$cd openssl-1.0.1g
$./config
$make
$sudo make install

error:
POD document had syntax errors at /usr/bin/pod2man line 69. make
tips:

rm /usr/bin/pod2man

2. nginx安装

$tar -zxvf nginx-1.8.0.tar.gz
$cd nginx.1.8.0
$groupadd -r nginx
$useradd -r -g nginx -s /bin/false -M nginx
$sudo ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=../pcre-8.38 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.1g --with-http_stub_status_module --user=nginx --group=nginx
$sudo make
$sudo make install

tips:
./configure参数中 –with-pcre=指向解压的源码目录

error:
make[2]: Entering directory `/usr/local/src/pcre2-10.10`
make[2]: *** No rule to make target `libpcre.la`. Stop.
make[2]: Leaving directory `/usr/local/src/pcre2-10.10`
make[1]: *** [../pcre2-10.10/.libs/libpcre.a] Error 2
make[1]: Leaving directory `/usr/local/src/nginx-1.8.0’
make: *** [build] Error 2
tips:
pcre2-10.10的问题,换个版本就解决了。具体为什么出问题我也不知道。

3. 安装成功
自动创建/usr/local/nginx
/usr/local/nginx目录

4. 手动启动

//不指定配置文件
sudo /usr/local/nginx/nginx
//指定配置文件
/usr/local/nginx/nginx -c /usr/local/nginx/nginx.conf

启动成功

5. 停止服务

$sudo kill `cat /usr/local/nginx/nginx.pid`

安装法二

$sudo apt-get install nginx
  • 配置文件 /etc/nginx/nginx.conf
  • 程序文件目录 /usr/sbin/nginx
  • 错误日志 /var/log/nginx/error.log
  • 启动脚本 /etc/init.d/nginx

安装法三【官网】

$sudo -s
#nginx=stable
#add-apt-repository ppa:nginx/$nginx
#apt-get update
#apt-get install nginx

安装成功后 nginx已启动
启动nginx成功

手动开启服务

方式一

$/etc/init.d/nginx start

开启失败时,检查/etc/init.d/nginx启动脚本
原脚本:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$NAME.pid \
              --exec $DAEMON
          echo "$NAME."
          ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
            exit 1
            ;;
    esac

    exit 0

方式二

/usr/sbin/nginx -c /etc/nginx/nginx.conf

成功开启
查看nginx进程

ps aux|grep nginx

查看nginx进程

访问http://localhost:80/index.html查看欢迎界面

停止服务

/etc/init.d/nginx -s stop

也可以直接kill掉nginx主进程

重启服务

/etc/init.d/nginx -s reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值