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实际编译安装的配置,修改
#! /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
安装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
相关文章推荐
- 构建Nginx服务器之一 安装及虚拟主机配置
- nginx安装 卸载 虚拟主机 负载均衡
- 11-4 12 Nginx安装 默认虚拟主机 用户认证 域名重定向
- Nginx安装、默认虚拟主机、用户认证、nginx中PHP解析
- Linux上nginx安装配置(配置虚拟主机,静态资源)
- shell之nginx安装+虚拟主机
- nginx安装,配置、虚拟主机、轮询、域名重定向
- Nginx 安装笔记(含PHP支持、虚拟主机、反向代理负载均衡)
- 运维之高级服务篇------ 4.Nginx常见问题处理、安装部署Tomcat服务器 、使用Tomcat部署虚拟主机
- nginx安装,配置、虚拟主机、轮询、域名重定向
- Nginx的安装与虚拟主机配置及HTTP和HTTPS共存配置
- Nginx安装简记(含PHP支持、虚拟主机、反向代理负载均衡)
- nginx安装及配置虚拟主机
- 编译安装Nginx实现网络访问多虚拟主机(wordpress+phpmyadmin)
- [Linux] Ubuntu_9.04_server安装nginx+php(fastcgi)+nginx虚拟主机配置格式
- linux 中安装nginx 的虚拟主机
- 12.6 Nginx安装;12.7 Nginx默认虚拟主机;12.8 Nginx用户认证;12.9 Nginx域名重定向
- Nginx安装、默认虚拟主机 、Nginx用户认证、Nginx域名重定向
- Nginx安装、默认虚拟主机、Nginx用户认证、Nginx域名重定向
- 12.6 Nginx安装 - 12.7 默认虚拟主机 - 12.8 Nginx用户认证 - 12.9 Nginx域名重定向