1.下载并安装nginx

到nginx官网上下载相应的安装包,http://nginx.org/en/download.html;

下载之后进行解压,将解压后的文件放到自己心仪的目录下,如下图所示:

至此,下载和安装nginx就已经完成了。

2.启动nginx

打开cmd命令窗口,切换到nginx解压目录下,输入命令 start nginx ,回车即可,此时可能会有一个黑色的弹窗一闪而过,不用理会。

打开浏览器,输入网址 http://localhost:80;回车,如果出现以下页面说明启动成功:

3.nginx常用命令

命令 描述
nginx -h 查看nginx帮助
nginx -v 查看nginx版本
nginx -t 测试nginx配置
nginx -T 测试nginx帮助,并打印配置信息
nginx -s reload 重新加载配置文件,平滑启动nginx
nginx -s stop 快速停止nginx
nginx -s quit 完整有序的停止nginx

4.nginx基本配置

nginx的配置文件在nginx解压目录/conf/nginx.conf,用编辑器打开即可进行相关配置


#user nobody; # 设置nginx服务的系统使用用户
worker_processes 1; # 工作进程数 #error_log logs/error.log; # nginx错误日志
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; # nginx服务启动时候的pid events {
worker_connections 1024; # 每个进程允许最大连接数
} http {
include mime.types;
default_type application/octet-stream; # access_log日志展示格式
# $remote_addr:客户端地址
# $remote_user:客户端请求nginx认证的用户名,默认不开启认证模块,没有记录
# $time_local: 客户端请求的时间
# $request:客户端请求的请求头
# $status: 请求的状态码
# $body_bytes_sent: 服务端相应客户端body信息的大小
# $http_referer: 访问当前页面的上一级页面地址
# $http_user_agent: 客户端浏览器的agent
# $http_x_forwarded_for:请求所携带的http信息 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 on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; # 连接超时时间 #gzip on; server {
listen 80; # 监听前端打开的80端口
server_name localhost; # 代理前端访问的地址 charset utf-8; #access_log logs/host.access.log main; location / {
root html; # 需要代理的前端页面代码目录(包含index.html等文件的目录)
index index.html index.htm;
} location /test/ {
proxy_pass http://127.0.0.1:8000/test/; # 将前端的/test/请求转发到后端哪个地址
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
# 静态资源文件
location /files/ {
root F:/nginx-1.12.2/nginx-1.12.2/;
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这个东东,突然觉得它是一把非常好的利器. 本文主要记录在windows下安装nginx,另参 ...

  2. windows下安装MongoDB扩展和配置

    windows下安装MongoDB扩展和配置 1.下载mongoDB扩展,根据当前php版本进行下载 地址如下:http://pecl.php.net/package/mongo 我本地php版本是 ...

  3. Windows下安装Nginx+php+mysql环境

    系统:Windows 7 64位系统 安装之前,首先下载软件: Nginx: http://nginx.org/en/download.html PHP Stable PHP 5.6.26: http ...

  4. mac下安装nginx及相关配置

    1. 安装 Homebrew   首先 homebrew是什么?它是Mac中的一款软件包管理工具,通过brew可以很方便的在Mac中安装软件或者是卸载软件.不了解的同学看以看官网(https://br ...

  5. Windows下安装Nginx及负载均衡

    1.下载Windows版本的Nginx http://nginx.org/en/download.html 2.解压Nginx包,配置conf文件下的nginx.conf文件 3.配置说明: #use ...

  6. windows 下安装nginx

    1.首先去官网下载 nginxWindows版本,官网下载:http://nginx.org/en/download.html 选择最新版本,下载到软件包后,解压文件包到指定目录,例如我的目录是D:\ ...

  7. windows下安装nginx,并添加至系统服务

    安装:解压修改配置文件运行即可 添加服务 需要借助"Windows Service Wrapper"小工具下载地址:winsw GitHub 下载后放在nginx目录下,并修改名字 ...

  8. windows 下安装 nginx + php

    1. 下载软件 需要的软件有nginx,php,mysql(如不需要可不安装) nginx.org,www.php.net上面有得下 全部解压出来 php基本不用做任何修改(下载直接解压版本的) 用c ...

  9. (转)Windows下安装Docker, GitBash环境配置

    转:https://blog.csdn.net/chengly0129/article/details/68944269 官网介绍: https://docs.docker.com/toolbox/t ...

随机推荐

  1. Swoole4-swoole创建Mysql连接池

    一 .什么是mysql连接池 场景:每秒同时有1000个并发,但是这个mysql同时只能处理400个连接,mysql会宕机. 解决方案:连接池,这个连接池建立了200个和mysql的连接,这1000个 ...

  2. python编程基础之十六

    for in 循环,与其说是循环不如说精确点交遍历 for 变量名 in + 迭代对象 语句A else: 语句B 作用:一次访问迭代对象中的元素并赋值给变量 循环终止时,执行else语句块,如果br ...

  3. 用到的Dos命令总结 持续更新

    1.xcopy命令:复制的扩展命令     常用参数:/s:复制空文件夹 不使用可能会造成文件混乱    /y忽略覆盖提示 使用/y会直接覆盖全部 例子:xcopy lark-UI\dist C:\U ...

  4. 1002. 写出这个数 (20)-PAT乙级真题

    读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字.输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各位数字之和的每一 ...

  5. Java零基础手把手系列:HashMap排序方法一网打尽

    HashMap的排序在一开始学习Java的时候,比较容易晕,今天总结了一些常见的方法,一网打尽.HashMap的排序入门,看这篇文章就够了. 1. 概述 本文排序HashMap的键(key)和值(va ...

  6. CentOS 7.7版本中NAT上网问题

    一.NAT(地址转换模式)概念 如果你的网络ip资源紧缺,但是你又希望你的虚拟机能够联网,这时候NAT模式是最好的选择.NAT模式借助虚拟NAT设备和虚拟DHCP服务器,使得虚拟机可以联网. 二.具体 ...

  7. [Luogu3112] [USACO14DEC]后卫马克Guard Mark

    题意翻译 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果叠 ...

  8. win-socket

    WIN32平台上的WINSOCK编程都要经过下列步骤: 定义变量->获得WINDOCK版本->加载WINSOCK库->初始化->创建套接字->设置套接字选项->关闭 ...

  9. vue-cli3 关闭一直运行的 /sockjs-node/info?t= ...

    首先 sockjs-node 是一个JavaScript库,提供跨浏览器JavaScript的API,创建了一个低延迟.全双工的浏览器和web服务器之间通信通道. 本地项目运行就会自动去访问:http ...

  10. jmeter-控制业务比例

    方式一: 多线程组 缺点:由于各事务相应时间一般不一致,故只能粗略的控制业务占比 实例:待补充