您的位置:首页 > 运维架构 > Nginx

nginx 安装 虚拟主机

2017-01-19 11:20 267 查看
nginx 安装
安装nginx依赖的库
[root@localhost src]# yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.4.4.tar.gz [root@localhost src]# tar zxvf nginx-1.4.4.tar.gz
[root@localhost src]# cd nginx-1.4.4
[root@localhost nginx-1.4.4]# ./configure 也可以用--help 查看选项 来安装
[root@localhost nginx-1.4.4]# make
[root@localhost nginx-1.4.4]# make install
安装完成后 启动nginx

[root@localhost ~]# /usr/local/nginx/sbin/nginx
配置脚本启动 停止ngix
下面的shell脚本内容,需要根据Nginx实际编译安装的配置,修改
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
lockfile=/var/lock/nginx.lock

nginx="/usr/sbin/nginx" 这三个参数
vim /etc/init.d/nginx   然后将下面的配置文件帖进来

配置文件如下

#! /bin/bash
#nx - 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
# pidfile: /var/run/nginx/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" // 我的nginx的路径
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" // 我的nginx的路径
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx // 我的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
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
-------------------------------------------------------------------------------[root@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig nginx on
[root@localhost ~]# chkconfig --list | grep nginx
nginx 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭

nginx虚拟主机配置
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name 123.com;
在访问机器上的hosts文件里配置域名 然后访问123.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  local