一、Nginx下载与安装

1、nginx官方下载地址:http://nginx.org/

2、下载完后将压缩包解压即可

3、nginx配置文件为根目录下conf\nginx.conf

二、Nginx常用命令说明

cmd进入nginx安装目录

tasklist /fi "imagename eq nginx.exe"    查看nginx进程
start nginx 启动nginx
nginx -s quit 安全关闭
nginx -s stop 强制关闭
nginx -s reload 改变配置文件时,重启nginx工作进程,使配置生效
nginx -s reopen 打开日志文件
nginx -v 查看版本
nginx -h 查看帮助信息

三、Nginx配置文件详解

#user  nobody;

# 指定nginx进程数
worker_processes 1; # 全局错误日志及PID文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
# 连接数上限
worker_connections 1024;
} #设定http服务器,利用它的反向代理功能提供负载均衡支持
http { #设定mime类型,类型由mime.type文件定义
include 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"'; # 使用哪种格式的日志
#access_log logs/access.log main; # sendfile 指令指定 nginx是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用
sendfile on;
#tcp_nopush on; # 连接超时时间
#keepalive_timeout 0;
keepalive_timeout 65; #开启gzip压缩,压缩html
#gzip on;
###################################
# 设定负载均衡的服务器列表 支持多组的负载均衡,可以配置多个upstream 来服务于不同的Server.
# nginx 的 upstream 支持几种方式的分配
# 1.轮询(默认)每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
# 2.weight 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
# 3.ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题
# 4.fair
# 5.url_hash #Urlhash
upstream mysvr{
#weigth参数表示权值,权值越高被分配到的几率越大
#1.down 表示当前的server暂时不参与负载
#2.weight 默认为1 weight越大,负载的权重就越大
#3.backup 其他所有的非backup机器down或者忙的时候,请求backup机器,所以这台机器的压力最轻,备用机器 #server 192.168.1.116 down;
#server 192.168.1.116 backup;
#server 192.168.1.142 weight=1;
server 192.168.1.142 weight=1;
}
##################################### # 配置代理服务器的地址,即Nginx安装的服务器地址、监听端口、默认地址
server {
#1.监听8099端口
listen 8099;
#对于server_name,如果需要将多个域名的请求进行反向代理,可以配置多个server_name来满足要求
server_name localhost;
#charset koi8-r; #access_log logs/host.access.log main; location / {
# 默认主页目录在nginx安装目录的html子目录
root html ;
index index.html index.htm;
#proxy_pass http://mysvr; #跟负载均衡服务器的upstream对应
}
#访问本地E:/source文件夹 访问路径为localhost:8099/file/a.png 实际访问路径为 E:/source/file/a.png
location /file/ {
root E:/source/;
autoindex on;
}
#error_page 404 /404.html; # redirect server error pages to the static page /50x.html
# 定义错误提示页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#}
}

Windows下nginx作为静态资源服务器使用的更多相关文章

  1. Windows下nginx配置多台服务器做负载均衡

    Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务. Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3 ...

  2. linux使用Nginx搭建静态资源服务器

    最近公司需要做一个宣传片播放  视频有点大 好几百M 就想到使用Nginx来代理静态资源,在过程中出现了一些问题,比如端口没开.访问是403等,没有成功,后面慢慢查找问题,才发现大部分博客资料的都不全 ...

  3. Nginx 作为静态资源服务器

    Nginx Windows 版本的启动停止,重新加载配置 启动 Windows版本下载解压后有一个nginx.exe可执行文件,双击启动. 启动后 浏览器访问http://127.0.0.1 可以看到 ...

  4. windows下nginx直接处理静态文件

    网上的沙雕们,你们发文章的时候就不能简单说明一下环境吗?老子都要看到一半才发现不是需要的类型 ji静态文件使用nginx直接处理,减轻tomcat压力 对于我的网站,静态文件有js css图片,然后图 ...

  5. [运维] 如何将 Linux 上的 nginx 变成 静态资源服务器 (二)

    环境 虚拟机上运行 Linux centos 7 64 已经安装 nginx-1.16.1.tar.gz  具体的安装过程可以参考 https://www.cnblogs.com/unityworld ...

  6. nginx搭建静态资源服务器

    nginx配置访问前端工程 1.前端工程目录 crm-view |-- view |-- user.html 2.工程位置 C:\Users\Administrator\Desktop\CRM系统\c ...

  7. 初始nginx(启动运行) 使用nginx做一个简单的静态资源服务器

    第一次接触nginx的时候,那时候公司还是用的一些不知名的小技术,后来公司发展问题,重新招了人,然后接触到nginx,公司 使用nginx用来做代理服务器,所有请求 都先经过nginx服务器,然后交由 ...

  8. Nginx——静态资源服务器(一)

    java web的项目中,我们经常将项目部署到Tomcat或者jetty上,可以通过Tomcat或者jetty启动的服务来访问静态资源.但是随着Nginx的普及,用Nginx来作为静态资源服务器,似乎 ...

  9. 使用node搭建静态资源服务器

    安装 npm install yumu-static-server -g 使用 shift+鼠标右键  在此处打开Powershell 窗口 server # 会在当前目录下启动一个静态资源服务器,默 ...

随机推荐

  1. LOJ 2172 「FJOI2016」所有公共子序列问题——序列自动机

    题目:https://loj.ac/problem/2172 在两个序列自动机上同时走,这样暴搜. 先走字典序小的字符,一边搜一边输出,就是按字典序排序的. 方案数很多,需要高精度?空间很小,要压位. ...

  2. 【luogu P2385 青铜莲花池】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2385 莲花池什么的最漂亮啦! 最近刷了两天搜索= =我搜索一直是弱菜 直接套bfs #include < ...

  3. Android学习笔记_51_转android 加载大图片防止内存溢出

    首先来还原一下堆内存溢出的错误.首先在SD卡上放一张照片,分辨率为(3776 X 2520),大小为3.88MB,是我自己用相机拍的一张照片.应用的布局很简单,一个Button一个ImageView, ...

  4. redis sentinel搭建以及在jedis中使用

    一.redis主从搭建 1.搭建redis master 1>redis安装 mkdir -p /usr/local/webserver/redis //安装目录 cd /usr/local/w ...

  5. 搭建基本的React Native开发环境

    步骤如下: 1.安装HomeBrew,命令如下: 在终端输入命令:$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Home ...

  6. D - 湫湫系列故事——减肥记II

    虽然制定了减肥食谱,但是湫湫显然克制不住吃货的本能,根本没有按照食谱行动! 于是,结果显而易见… 但是没有什么能难倒高智商美女湫湫的,她决定另寻对策——吃没关系,咱吃进去再运动运动消耗掉不就好了? 湫 ...

  7. 使用Linux命名将代码上传到GitHub

    GitHub代码上传教程 https://my.oschina.net/baishi/blog/520791 这篇文章讲得挺清楚的,但是在上传的时候出现了问题 ! [rejected] master ...

  8. MySQL数据库常见报错原因

    1.启动数据库时报错 启动 # /etc/init.d/mysqld start Starting MySQL.Logging to '/application/mysql-5.6.36/data/m ...

  9. [异常笔记]poi读取Excel异常

    Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException: The sup ...

  10. 编程 - 前端 - JavaScript - 库 - ECharts (开源可视化)

    ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox,Safari等) ...