nginx服务

优势

1.高性能,近w个连接请求时,他的响应要比其他的web要快。
2.高扩展性:nginx功能模块化。官方提供了很多的优秀模块。
3.高可靠性:9999  99999 
4.热部署:不停止服务的情况下进行升级。 
5.互联网公司都选择Nginx  代理、缓存、负载均衡、静态资源处理、动静分离、LNMP、LNMT、LNMG 架构。

应用场景

1. web服务
2. 负载均衡
3. 代理缓存
4. 安全服务 Https Lua
5. 动静分离 Nginx+Tomcat
6. 静态资源服务

配置文件

[root@web01 ~]# cat  /etc/nginx/nginx.conf
#全局配置( 作用于整个Nginx )
user  www;					# nginx进程是哪个用户来运行
worker_processes  2;				# 启动多少个worker进程
error_log  /var/log/nginx/error.log warn;	# 错误日志存在哪里( 黑匣子 )
pid        /var/run/nginx.pid;			# 每个进程运行起来都会存在一个pid文件,里面存放的是该进程的 ID  

# 事件驱动模型
events {
worker_connections  1024;		#worker接收的连接数  1024 * worker_process = connections
}

# http模型
http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;		#当nginx无法识别你这个文件时,则默认一访问就直接下载了。

#定义日志的格式
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;	#访问日志的路径

sendfile        on;
#tcp_nopush     on;
keepalive_timeout  65;		#长连接 ( 默认长连接保持 65s )
#gzip  on;				#压缩

include /etc/nginx/conf.d/*.conf;	#包含/etc/nginx/conf.d/目录下的所有以 .conf 结尾的文件。
}

www.game.com.conf

server {					#server表示要配置网站,每个Server{} 代表一个网站,简称虚拟主机
listen       80;				#这个网站监听80端口
server_name  qwe.com;			#这个网站的域名是什么

location / {				#控制网站访问的路径
    root   /usr/share/nginx/html;		#定义网站源代码存放的路径
    index  index.html index.htm;		#默认返回哪个文件作为默认返回页
	}
}

运行一个游戏网站

1.准备一个游戏的源码   (  qq下载的  )
2.准备一个目录,存放我们的游戏
	[root@web01 ~]# mkdir /code
	[root@web01 ~]# cd /code
	[root@web01 code]# rz  游戏
	[root@web01 code]#  unzip h5game.zip
3.配置Nginx
	1. 配置监听的端口
	2. 配置网站的域名
	3. 配置用户访问网站路径规则  location
	4. 配置默认返回的页面
[root@web01 ~]# cat /etc/nginx/conf.d/game.yang.com.conf
  server {
		listen 80;
		server_name game.yang.com;

	location / {
			root /code;
			index index.html;
	}
  }


4.检查nginx的语法  {} 成对出现  ; 每一条指令的结尾都有
	[root@web01 code]# nginx -t
	nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
	nginx: configuration file /etc/nginx/nginx.conf test is successful
5.重启服务,让配置生效
	[root@web01 code]# systemctl restart nginx
6.域名解析(host劫持)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值