安装包:nginx-1.8.0.tar.gz
挂载Windows盘
mount -t cifs -o username=xx,passwd=yyyy //IP地址/share /mnt
解压nginx包到/usr/src/
sudo tar -zxf nginx-1.8.0.tar.gz -C /usr/src/
创建nginx用户和组
cat /etc/group
sudo groupadd –g 112 –r nginx
sudo useradd –u 112 –r –g 112 nginx
id nginx
uid=112(nginx) gid=112(nginx) groups=112(nginx)
编译nginx
cd /usr/src/nginx-1.8.0
sudo ./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--with-pcre
错误:
./configure:error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using--without-http_rewrite_module
option, or install the PCRE library intothe system, or build the PCRE library
statically from the source with nginx byusing --with-pcre=<path> option.
缺少pcre-devel包
解决:
Centos :yum installpcre-devel 就可以解决
Ubuntu : sduo apt-get pcre-devel 找不到pcre-devel包,debian/ubuntu系统下名称改了,名称为libpcre3 libpcre3-dev 正确命令如下:
sudoapt-get install libpcre3 libpcre3-dev
继续编译nginx
错误:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules,or install the OpenSSL library
into the system, or build the OpenSSLlibrary statically from the source
with nginx by using --with-openssl=<path>option.
缺少openssl libssl-dev包
解决:
Centos:yum install openssl-devel
Ubuntu: sudo apt-get install openssl libssl-dev
重新编译成功
sudo make
错误:
mkdir: cannot create directory ‘/usr/local/nginx’: Permission denied,创建/usr/src/nginx权限不够,我用sudo不知道为什么还是权限不够,后来直接mkdir /usr/src/nginx 问题OK
解决:sudo mkdir /usr/src/nginx
sudo make && make install
安装完成
启动nginx
nginx 启动文件在--sbin-path=/usr/sbin/nginx
sudo cp /usr/sbin/nginx /etc/init.d/
sudo service nginx 启动nginx
错误:
nginx: [emerg] mkdir() "/var/tmp/nginx/client"failed (2: No such file or directory)没有
/var/tmp/nginx/client 目录
解决:
sudo mkdir -p /var/tmp/nginx/client
sudo service nginx
查看端口
sudo netstat –ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23451/nginxtcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1106/sshdtcp6 0 0 :::22 :::* LISTEN 1106/sshdudp 0 0 0.0.0.0:68 0.0.0.0:* 826/dhclientudp 0 0 0.0.0.0:23296 0.0.0.0:* 826/dhclientudp6 0 0 :::43770 :::* 826/dhclient开机自动启动chkconfig
Ubuntu 不支持chkconfig,需安装
Chkconfig.deb下载地址:
dpkg –I chkconfig.deb
sudo chkconfig --add nginx
sudo chkconfig nginx on
错误:
/sbin/insserv: Nosuch file or directory
解决:
sudo find / -name insserv
sudo ln -s /usr/lib/insserv/insserv /sbin/ 软链接到/sbin/
sudo chkconfig nginx on chkconfig –list 查看nginx 服务是OK的,但报以下错误:
niliyan@ubuntu2:/var/log$ sudo chkconfignginx on
insserv: warning: script 'K20nginx' missingLSB tags and overrides
insserv: warning: script 'nginx' missingLSB tags and overrides
The script you are attempting to invoke hasbeen converted to an Upstart
job, but lsb-header is not supported forUpstart jobs.
insserv: warning: script'friendly-recovery' missing LSB tags and overrides
insserv: Default-Start undefined, assumingempty start runlevel(s) for script `friendly-recovery'
insserv: Default-Stop undefined, assuming empty stop runlevel(s) for script `friendly-recovery'
The script you are attempting to invoke hasbeen converted to an Upstart
job, but lsb-header is not supported forUpstart jobs.
insserv: warning: script 'cron' missing LSBtags and overrides
insserv: Default-Start undefined, assumingempty start runlevel(s) for script `cron'
insserv: Default-Stop undefined, assuming empty stop runlevel(s) for script `cron'
在网上查了很久,chkconfig适用于redhat,ubuntu/debian应该使用update-rc.d 命令,可以用sudo update-rc.dnginx defaults 来替代sudochkconfig nginx on 启动nginx
sudorm -rf /sbin/insserv update-rc.d 可以不需要软件接,删除
sudoupdate-rc.d nginx defaults
update-rc.d:warning: /etc/init.d/nginx missing LSB information
update-rc.d:see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/nginx...
/etc/rc0.d/K20nginx -> ../init.d/nginx
/etc/rc1.d/K20nginx -> ../init.d/nginx
/etc/rc6.d/K20nginx -> ../init.d/nginx
/etc/rc2.d/S20nginx -> ../init.d/nginx
/etc/rc3.d/S20nginx-> ../init.d/nginx
/etc/rc4.d/S20nginx -> ../init.d/nginx
/etc/rc5.d/S20nginx -> ../init.d/nginx
sudo chkconfig --list |grep nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
访问测试