Ubuntu下安装nginx的步骤分享

2020-02-03 10:50:41王振洲

4)、解决了以上问题,编译nginx就没啥问题了。下面安装。(附加安装插件的方法)
  先下载插件并解压

复制代码
sudo wget https://github.com/agentzh/echo-nginx-module/tarball/v0.40rc1 -O echo-nginx-module.tar.gz
sudo wget https://nodeload.github.com/agentzh/memc-nginx-module/tarball/v0.13rc3 -O memc-nginx-module.tar.gz
sudo tar -xzvf echo-nginx-module.tar.gz
sudo tar -xzvf memc-nginx-module.tar.gz  

进入nginx目录cd nginx-1.2.2/,执行以下命令

复制代码
./configure --user=www-data --group=www-data --with-debug --with-http_gzip_static_module --with-http_ssl_module --with-pcre=../pcre-8.31/ --with-http_perl_module --with-perl=/usr/bin/perl --with-http_stub_status_module --with-http_realip_module
--prefix=/usr/local/nginx
--add-module=../agentzh-echo-nginx-module-9259898/
--add-module=../agentzh-memc-nginx-module-4007350/
注:前面一段是一些编译参数,后面add-module是添加模块
make -j2
make install

大爷的,又可能报错。没有nginx,logs目录访问权限

复制代码
[alert]: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2011/03/21 06:09:33 [emerg] 24855#0: mkdir() "/usr/local/nginx/client_body_temp" failed (13: Permission denied)   

解决办法:

复制代码
sudo chmod a+rwx -R logs
sudo chmod a+rwx -R /usr/local/nginx   

现在,差不多没问题了。
可以进入/usr/local/nginx/sbin/执行以下命令看是否成功:
  nginx -v
5)、nginx自启动
编辑启动脚本:

复制代码
sudo vim /etc/init.d/nginx


复制代码
#! /bin/bash
#
# nginx Start up the nginx server daemon
#
# chkconfig: 2345 55 25
# Description: starts and stops the nginx web server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: starts and stops the nginx web server
### END INIT INFO
# To install:
# copy this file to /etc/init.d/nginx
# shell> chkconfig --add nginx (RedHat)
# shell> update-rc.d -f nginx defaults (debian)
# To uninstall:
# shell> chkconfig --del nginx (RedHat)
# shell> update-rc.d -f nginx remove
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/var/local/nginx/logs/$NAME.pid
ULIMIT=10240
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
echo "Starting $NAME ..."
ulimit -SHn $ULIMIT
$DAEMON -c $CONFIGFILE