nginx基础知识

nginx安装

角色外网ip内网ip主机名
webeth0:10.0.0.7eth1:172.16.1.7web01
  • [root@web01 ~]# cat /etc/yum.repos.d/nginx.repo
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/ r e l e a s e v e r / releasever/ releasever/basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true

在web01机器下载nginx
[root@web01 ~]# yum install nginx -y

nginx的配置文件
[root@web01 ~]# cat /etc/nginx/nginx.conf
user nginx; # Nginx进程的运行用户身份
worker_processes 1; # Nginx运行的worker进程数
error_log /var/log/nginx/error.log warn; # Nginx错误日志存放的路径
pid /var/run/nginx.pid; # Nginx进程运行的PID号

events {
	worker_connections  1024;			                               	#每个worker进程能接受的最大连接数
	use epoll;
}


http {
	include       /etc/nginx/mime.types;
	default_type  application/octet-stream;

	#日志格式
	log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
					  '$status $body_bytes_sent "$http_referer" '
					  '"$http_user_agent" "$http_x_forwarded_for"';
	
	#访问日志的路径  访问日志的存储格式是main格式, main格式在log_format中进行定义
	access_log  /var/log/nginx/access.log  main;		

	sendfile        on;
	#tcp_nopush     on;
	keepalive_timeout  65;					#超时时间
	#gzip  on;
	include /etc/nginx/conf.d/*.conf;		#包含  *.conf
	
	
	#server<--定义网站
	server {
		listen       80;							#监听80端口
		server_name  localhost;						#网站的域名
		
		location / {								#匹配网站的uri
			root   /usr/share/nginx/html;			#返回资源的具体路径
			index  index.html index.htm;			#返回的具体资源名称
		}
}


http					<---负责请求与响应
*	server1				<---定义一个具体的网站
*		location 		<---根据用户请求的uri 进行匹配
*		location2
*		location3
*	server2
*		location 		<---根据用户请求的uri 进行匹配
*		location2
*		location3
*	server....
  • nginx运行一个网站,新增一个server配置就是增加一个网站
    [root@web01 conf.d]# vim game.oldxu.com.conf 配置一个游戏网站
    server {
    listen 80;
    server_name game.oldxu.com;
    location / {
    root /code/;
    index index.html;
    }
    }
  • 语法检查
  • nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    重启nginx
    [root@web01 code]# systemctl restart nginx

准备好代码的位置
[root@web01 conf.d]# mkdir /code
[root@web01 conf.d]# cd /code/
上传代码
[root@web01 code]# git clone https://gitee.com/linex/battlecity.git
[root@web01 code]# mv battlecity/* ./
小霸王游戏
在增加一个网站
[root@web01 code2]# vim /etc/nginx/conf.d/html.oldxu.com.conf
server {
listen 80;
server_name html.oldxu.com;

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

语法检查
[root@web01 code2]# nginx -t
重启服务
[root@web01 code2]# systemctl restart nginx
创建代码存放位置
[root@web01 ~]# mkdir -p /code2
[root@web01 ~]# cd /code2
上传代码
软件包
配置域名劫持
配置域名劫持
在浏览器输入域名
html游戏平台

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值