相关目录html
# 主目录 /usr/local/nginx # 配置文件路径 /usr/local/nginx/conf/nginx.conf # linux 安装目录\conf\nginx.conf # Windows # 静态文件路径 /usr/local/nginx/html/
启动linux
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf # 看到以下显示说明启动成功 ''' nginx.conf syntax is ok nginx.conf test is successful '''
重启nginx
/usr/local/nginx/sbin/nginx -s reload
查看进程是否启动负载均衡
ps -ef|grep nginx
查看端口号是否占用ide
netstat -tunlp|grep 端口号
强制中止网站
pkill -9 nginx
验证nginx配置文件是否正确spa
/usr/local/nginx/sbin/nginx -t # 看到以下显示说明配置文件正确 ''' nginx.conf syntax is ok nginx.conf test is successful '''
基于域名的虚拟主机code
经过不一样的域名区分不一样的虚拟主机,基于域名的虚拟主机是企业应用最广的虚拟主机类型,几乎全部对外提供服务的网站使用的都是基于域名的主机server
配置:修改nginx配置文件配置多域名,重启nginx服务,建立对应的不一样站点目录并上传站点文件,也可都使用一个站点目录,经过多域名来访问htm
server{ listen 80; server_name www.aaa.com; location / { root html/aaa; index index.html index.htm; } } server{ listen 80; server_name www.bbb.com; location / { root html/bbb; index index.html index.htm; } } server{ listen 80; server_name www.ccc.com; location / { root html/ccc; index index.html index.htm; } }
基于端口的虚拟主机
经过不一样的端口来区分不一样的虚拟主机,此类虚拟主机对应的企业应用主要为公司内部的网站,例如:一些不但愿直接对外提供用户访问的网站后台等,访问基于端口的虚拟主机,地址里要带有端口号,例如http://www.test.com:81 http://www.test.com:82等
server{ listen 80; server_name localhost; location / { root html/aaa; index index.html index.htm; } } server{ listen 81; server_name localhost; location / { root html/bbb; index index.html index.htm; } } server{ listen 82; server_name localhost; location / { root html/ccc; index index.html index.htm; } }
基于IP的虚拟主机
经过不一样的IP区分不一样的虚拟主机,此类虚拟主机对应的企业应用很是少见,通常不一样的业务须要使用多IP的场景都会在负载均衡上进行IP绑定。
server{ listen 10.0.0.7:80; server_name www.aaa.com; location / { root html/aaa; index index.html index.htm; } } server{ listen 10.0.0.8:80; server_name www.bbb.com; location / { root html/bbb; index index.html index.htm; } } server{ listen 10.0.0.9:80; server_name www.ccc.com; location / { root html/ccc; index index.html index.htm; } }
其余配置
修改上传文件大小限制
Nginx 默认是对上传的文件大小有限制的,咱们能够修改相应配置来修改对文件大小的限制
# 在http{}段落增长以下参数 client_max_body_size 20M; # 20M能够换为任何大小