前言:
今天你们对“nginx服务器安装”大约比较重视,我们都需要剖析一些“nginx服务器安装”的相关文章。那么小编也在网摘上搜集了一些有关“nginx服务器安装””的相关资讯,希望各位老铁们能喜欢,各位老铁们快快来学习一下吧!1、 Nginx的下载
可以从以下网络连接进行下载nginx的不同版本:
2、 Nginx的安装
Nginx分为windows和linux下的安装,本文以linux版本Centos为例,其他linux发行版本都大致相同,进行Nginx的源码编译安装,如果有想了解windows安装的,请自行网上查询,也可以私聊我。
2.1、使用上传工具将Nginx上传到Centos内。
2.2、安装Nginx的依赖软件
yum install gcc openssl-devel pcre-devel zlib-devel
2.3、创建nginx用户
#groupadd –r nginx
#useradd -r -g nginx -s /bin/false -M nginx
2.4、编译安装
#./configure \
--prefix=/usr/local \ 指定安装路径
--sbin-path=/usr/sbin/nginx \ 指定Nginx可执行文件安装路径
--conf-path=/etc/nginx/nginx.conf \ 指定nginx.conf文件的路径
--error-log-path=/var/log/nginx/error.log \ 指定error.log文件的路径
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \ 指定pd指令的路径
--lock-path=/var/lock/nginx.lock \
--user=nginx \ 指定Nginx的用户为nginx
--group=nginx \ 指定Nginx的所属组为nginx
--with-http_ssl_module \ 打开使用HTTP SSL模块
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \ 指定http客户端请求缓存文件存放目录的路径。
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 指定http反向代理缓存文件存放目录的路径
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 指定http fastCGI缓存文件存放目录的路径。
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre 打开pcre库的使用
表示编译成功
# make && make install
注:
关于配置选项的简单说明:
--prefix=<path> - The path relative to which all other Nginx paths will resolve. If not specified, defaults to /usr/local/nginx.
--sbin-path=<path> - The path to the nginx executable. Only used for installation. If not specified defaults to <prefix>/sbin/nginx.
--conf-path=<path> - The default location of nginx.conf if no -c parameter is provided. If not provided, defaults to <prefix>/conf/nginx.conf.
--pid-path=<path> - The path to nginx.pid, if not set via the "pid" directive in nginx.conf. If not provided, defaults to <prefix>/logs/nginx.pid.
--error-log-path=<path> - The location of the error log if not set via the "error_log" in nginx.conf. If not set, defaults to <prefix>/logs/error.log.
--http-log-path=<path> - The location of the access log if not set via the "access_log" directive in nginx.conf. If not set, defaults to <prefix>/logs/access.log.
--user=<user> - The default user that nginx will run as if not set in nginx.conf via the "user" directive. If not set, defaults to "nobody".
--group=<group> - The default group that nginx will run under if not set via the "user" directive in nginx.conf. If not set defaults to "nobody".
--with-http_ssl_module - Enable ngx_http_ssl_module. Enables SSL support and the ability to handle HTTPS requests. Requires OpenSSL. On Debian, this is libssl-dev.
--with-http_flv_module - Enable ngx_http_flv_module
--http-client-body-temp-path=PATH - Set path to the http client request body temporary files. If not set, defaults to <prefix>/client_body_temp
--http-proxy-temp-path=PATH - Set path to the http proxy temporary files. If not set, defaults to <prefix>/proxy_temp
--http-fastcgi-temp-path=PATH - Set path to the http fastcgi temporary files. If not set, defaults to <prefix>/fastcgi_temp
--lock-path=<path> - The path to the nginx.lock file. If not provided, defaults to <prefix>/logs/nginx.lock.
3、 将以下存放在/etc/rc.d/init.d/目录下,并命名为nginx(或者其他的,你自己记得住即可),就可以使用servie服务进行Nginx开启、关闭、重启。
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
sleep 1
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
4、 测试。
/usr/local/nginx/sbin启动nginx
Service nginx start ,然后执行netstat –tunlp ,查看是否有80端口开放,此时Nginx就编译安装成功。
注:需要关闭防火墙和selinux
5、 如果写的好,请继续关注我哦,下一章讲《Nginx的基本配置与优化》。
标签: #nginx服务器安装 #nginxwin安装配置