Nginx

安装nginx及其依赖

安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装

yum install -y gcc gcc-c++

PCRE pcre-devel 安装

yum install -y pcre pcre-devel

zlib 安装

yum install -y zlib zlib-devel

OpenSSL 安装

yum install -y openssl openssl-devel

nginx_upstream_jvm_route
nginx_upstream_jvm_route 是一个nginx的扩展模块,用来实现基于 Cookie 的 Session Sticky 的功能。

yum install -y pcre-devel zlib-devel openssl-devel 

在这里插入图片描述

下载上述源码包
将其统一上传到服务器指定路径下,如/home/softinstall/nginx

配置服务并设置开机启动

编写服务脚本

#!/bin/sh
#
# chkconfig: 35 80 20
# description: nginx Servlet Container
#
#
# match these values to your environment:

# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
prog="nginx"
NGINX=/usr/local/nginx

start() {

 $NGINX/sbin/nginx
 echo $"Starting $prog: "
 return $RETVAL
  }

stop() {

 $NGINX/sbin/nginx -s stop
 echo $"Stopping $prog: "
  }

# See how we were called.
case "$1" in
start)
   start
   ;;
 stop)
  stop
   ;;
 status)
   status $prog
   RETVAL=$?
   ;;
 restart)
   stop
   start
   ;;
  *)
echo "nginx service is;Usage: $0 {start|stop|restart}"
   ;;
esac
exit $RETVAL

执行如下指令

chmod 755 /etc/rc.d/init.d/nginx
chkconfig nginx on

重启和启动服务
在这里插入图片描述

查看nginx
在这里插入图片描述

进入目录操作nginx
nginx执行文件在/usr/local/nginx/sbin/nginx

//进入到sbin目录
cd /usr/local/nginx/sbin/

./nginx //启动

./nginx -s stop //快速停止

./nginx -s reload //重新加载配置文件

快速退出

/nginx -s stop

配置基于域名的虚拟主机

一、创建站点目录

mkdir -p / www/ {web/ ,blog/}

二、配置站点首页文件

echo "welcom to pengqinxin 's web-server ">>/www/web/index.html
echo "welcom to pengqinxin 's blog-server ">>/www/blog/index.html

三、配置基于域名的虚拟主机

cd /usr/ local/nginx/ conf/
vim nginx.conf
server{
			listen 80;
			server_name www.yyy.com;
			location / {
							root /www / web;
							index index.html index.htm;
							}
			}
server{
			listen 80;
			server_name blog.yyy.com ;
			location / {
							root /www/ blog;
							index index.html index.htm
			}
	   }

四、配置自己电脑hosts文件
C:\Windows\System32\drivers\etc

选择hosts文件,以管理员模式打开

在最后面加上自己的IP地址和自己添加的域名,保存退出

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值