标签:nginx nginx安装 nginx配置 编译安装nginx nginx编译
三、安装配置nginx 官网www.nginx.org
(1)解决依赖安装 yum -y install gcc gcc+ gcc-c++ gd zlib zlib-devel openssl openssl-devel autoconf automake
创建nginx运行所需要的用户
[root@nginx ~]# groupadd -r -g 108 nginx
[root@nginx ~]# useradd -r -u 108 -g 108 nginx -s /sbin/nologin
(2)安装pcre
[root@nginx ~]#tar -jxf pcre-8.36.tar.bz2
[root@nginx ~]#cd pcre-8.36
[root@nginx ~]# ./configure
[root@nginx ~]#make && make install
(3)安装nginx
[root@nginx ~]# tar -zxvf nginx-1.9.0.tar.gz
[root@nginx ~]# cd nginx-1.9.0
[root@nginx ~]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --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/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_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/fcsi --with-pcre --with-http_flv_module --with-http_gzip_static_module
[root@nginx ~]# make && make install
(4)启动nginx:
#/usr/sbin/nginx
nginx: [emerg] getpwnam("nginx") failed
提示需要创建nginx用户和组:
再次运行就好了,如果出现下面错误,手工创建相应目录就好:
nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
[root@nginx-backup /]# mkdir -p /var/tmp/nginx/client
[root@nginx-backup init.d]# ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1
(5)自己开发,添加nginx启动脚本
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
(6)/usr/local/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 启动nginx -c指定配置文件路径
(7)[root@nginx-master ~]# ps -ef | grep nginx 通过ps查找nginx主进程号master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
(8)查看启动状态,端口监听一般就成功
[root@nginx ~]# netstat -tulnp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3373/nginx
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 3373/nginx
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 3373/nginx
[root@nginx ~]# ps -ef | grep nginx
root 3373 1 0 10:03 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 3374 3373 0 10:03 ? 00:00:00 nginx: worker process
nginx 3375 3373 0 10:03 ? 00:00:00 nginx: worker process
nginx 3376 3373 0 10:03 ? 00:00:00 nginx: worker process
nginx 3377 3373 0 10:03 ? 00:00:00 nginx: worker process
nginx 3378 3373 0 10:03 ? 00:00:00 nginx: worker process
nginx 3379 3373 0 10:03 ? 00:00:00 nginx: worker process
root 3446 2515 0 10:03 pts/0 00:00:00 grep nginx
[root@nginx ~]#
(9)打开浏览器访问:http://你的ip+端口/ 默认是80
出现下面消息,配置成功。
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
本文出自 “山猫” 博客,谢绝转载!
标签:nginx nginx安装 nginx配置 编译安装nginx nginx编译
原文地址:http://cqtangbo.blog.51cto.com/2978612/1754174