Nginx安装配置详解

php论坛  2015-01-30 03:58:36  来源:1  阅读:91

yum install nginx

启动 sbin/nginx 重启 /usr/sbin/nginx -s  reload 

/usr/share/nginx/html


首先执行命令找到nginx路径
ps aux | grep nginx
如nginx路径为
/usr/local/nginx/sbin/nginx

然后执行以下命令
/usr/local/nginx/sbin/nginx -V
默认放在 安装目录下 conf/nginx.conf



3)开机自启动nginx

这里使用的是编写shell脚本的方式来处理

vi /etc/init.d/nginx  (输入下面的代码)


#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

建设虚拟机 /etc/nginx/nginx.conf


http

{


 #第一个虚拟主机
    server
    {
       #监听的端口
       listen     80;
       #主机名称
       server_name   aaa.domain.com
       #访问日志文件存放路径
       access_log     log/aaa.domain.com.access.log combined;
       location/
       {
       #默认首页文件,顺序从左到右,如果找不到index.html文件,则查找index.htm文件作为首页文件
       index index.html  index.htm;
       #HTML网页文件存放的目录
       root   /data0/htddocs/aaa.domain.com;
分享到:

0条评论网友评论

  • 全部评论
加载更多

飞翔船舶

关于飞翔 | 联系我们 | 新手教程 | 隐私声明 | 经营优势 | 常见问题

Copyright © 2010 - 2012 Tencent. All Rights Reserved  工信部备案号:备案号:ICP备1100256