nginx 常用命令和配置

nginx 命令和配置

常用命令

启动

./nginx

检查 nginx.conf 配置文件

./nginx -t

重启

./nginx -s reload

停止

./nginx -s stop

nginx 配置

基本配置

# 全局区	有一个工作子进程,一般设置为 CPU 数 * 核数
worker_processes	1;

events {
	# 一般是配置 nginx 进程与连接的特性
	# 如 1 个 work 能同时允许多少连接,一个子进程最大允许连接 1024 个连接
	worker_connections	1024;
}

# 配置 HTTP 服务器配置段
http {
	# 配置虚拟主机段
	server {
		# 定位,把特殊的路径或文件再次定位
		location {
		}
	}
	
	server {
		...
	}
}

基于域名的虚拟主机

# 在 http 大括号中添加如下代码段
server {
	# 监听端口 80
	listen				80;
	
	# 监听域名 abc.com
	server_name	abc.com

	location / {
		# 相对路径,相对 nginx根目录。也可写成绝对路径
		root			abc

		# 默认跳转到 index.html 页面
		index		index.html
	}
}

基于端口的虚拟主机配置

server {
	listen				2022;
	server_name	abc.com;
	location / {
		root			/home;
		index		index.html
	}
}

基于 IP 地址虚拟主机配置

server {
	listen				80;
	server_name	139.199.94.62;
	location / {
		root			ip;
		index		index.html;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值