Nginx 是一个高性能的http 和反向代理服务器,也是一个代理服务器。

  Nginx比Apache 更加轻量级,占用的资源少,抗并发,二apache是阻塞型的,在高并发下,nginx更占优势。

  我们先从官网上面下载一个windows版本的nginx。http://nginx.org/en/download.html

  

  配置文件:解压后,找到nginx.conf    我下载的是1.8

  

#user  nobody;
worker_processes 1; #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 {
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 on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #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;
# }
#} }

  nginx 集群的配置

  

#######################################所有的指定必须由分号结束#######################################
#user nobody; ######### 配置用户或者组
worker_processes 1; ######## 允许生成的进程数 #error_log logs/error.log;
#error_log logs/error.log notice; ########### 制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
#error_log logs/error.log info; #pid logs/nginx.pid; ############ 指定运行文件存放的地址 events {
accept_mutex on; ########## 设置网路连接序列化,防止惊群现象发生,默认为on
multi_accept on; ######### 设置一个进程是否同时接受多个网络连接,默认为off
#use epoll; ########## 事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
worker_connections 1024; ############ 最大连接数
} http {
include mime.types; ########文件扩展名与文件类型映射表
default_type application/octet-stream; ########默认文件类型,默认为text/plain #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; ############# combined为日志格式的默认值 sendfile on; ############### 允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
#tcp_nopush on;
#sendfile_max_chunk 100k; ################# 每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。 #keepalive_timeout 0;
keepalive_timeout 65; ############### keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。 #gzip on; upstream myservice {
server 127.0.0.1:7878 weight=1;
server 192.168.10.121:3333 weight=1; #热备
#ip_hash; ####### nginx会让相同的客户端ip请求相同的服务器 解决session共享的问题
} #error_page 404 https://www.baidu.com; ####### 错误页
#proxy_intercept_errors on; ######## 如果被代理服务器返回的状态码为400或者大于400,设置的error_page配置起作用。默认为off。
#proxy_method get; ######## 支持客户端的请求方法。post/get;
#proxy_http_version 1.0 ; ####### Nginx服务器提供代理服务的http协议版本1.0,1.1,默认设置为1.0版本
#proxy_connect_timeout 1; ###### nginx服务器与被代理的服务器建立连接的超时时间,默认60秒
#proxy_read_timeout 1; ######## nginx服务器想被代理服务器组发出read请求后,等待响应的超时间,默认为60秒。
#proxy_send_timeout 1; ####### nginx服务器想被代理服务器组发出write请求后,等待响应的超时间,默认为60秒。 server {
keepalive_requests 120; ######## 单连接请求上限次数。
listen 80; ######## 监听端口
server_name localhost; ######## 监听地址 #charset koi8-r; #access_log logs/host.access.log main; location / { ###### 请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
root html; #### 根目录
index index.html index.htm; ##### 设置默认页
proxy_pass http://myservice; ###### 请求转向mysvr 定义的服务器列表
#deny 127.0.0.1; ##### 拒绝的ip
#allow 172.18.5.54; ##### 允许的ip
} #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;
# }
#} }

   nginx的启动和关闭(*****nginx启动不像tomcat启动有弹框,刚开始时,容易入这个坑,以为没有启动******)

  

nginx 关闭   使用windows 的时候出现很多的服务 可以使用这个关闭   taskkill /F /IM nginx.exe

本人建议使用命令的方式进行启动

启动Nginx:start nginx

 

快速停止或关闭Nginx:nginx -s stop

 

正常停止或关闭Nginx:nginx -s quit

 

配置文件修改重装载命令:nginx -s reload

上面会引发session共享的问题

nginx 新手入门的更多相关文章

  1. nginx新手入门

    nginx的应用 官网(nginx.org) nginx可以做1.web服务(http服务)2.http代理服务3负载均衡在官网(nginx.org)如下图处下载先点击 跳转下一页点击(nginx/w ...

  2. nginx 学习笔记(2) nginx新手入门

    这篇手册简单介绍了nginx,并提供了一些可以操作的简单的工作.前提是nginx已经被安装到你的服务器上.如果没有安装,请阅读上篇:nginx 学习笔记(1) nginx安装.这篇手册主要内容:1. ...

  3. 即时通讯新手入门:一文读懂什么是Nginx?它能否实现IM的负载均衡?

    本文引用了“蔷薇Nina”的“Nginx 相关介绍(Nginx是什么?能干嘛?)”一文部分内容,感谢作者的无私分享. 1.引言   Nginx(及其衍生产品)是目前被大量使用的服务端反向代理和负载均衡 ...

  4. nginx配置入门

    谢谢作者的分享精神,原文地址:http://www.nginx.cn/591.html nginx配置入门 之前的nginx配置是对nginx配置文件的具体含义进行讲解,不过对于nginx的新手可能一 ...

  5. nginx 配置入门

    之前的nginx配置是对nginx配置文件的具体含义进行讲解,不过对于nginx的新手可能一头雾水. 今天看到个文档不错,翻译过来分享给大家,可以让新手更详细地了解nginx配置,可以说是nginx配 ...

  6. Docker新手入门:基本用法

    Docker新手入门:基本用法 1.Docker简介 1.1 第一本Docker书 工作中不断碰到Docker,今天终于算是正式开始学习了.在挑选系统学习Docker以及虚拟化技术的书籍时还碰到了不少 ...

  7. 《IM开发新手入门一篇就够:从零开发移动端IM》

        登录 立即注册 TCP/IP详解 资讯 动态 社区 技术精选 首页   即时通讯网›专项技术区›IM开发新手入门一篇就够:从零开发移动端IM   帖子 打赏 分享 发表评论162     想开 ...

  8. 【代理是什么?】nginx快速入门+反向代理hexo个人博客

    @ 目录 前言 本文说明 请大家务必查看 工作原理 正向代理 反向代理 环境准备 详细版 入门:搭建步骤 配置阿里云epel源: yum安装nginx: 启动nginx: 配置default.conf ...

  9. 新手入门指导:Vue 2.0 的建议学习顺序

    起步 1. 扎实的 JavaScript / HTML / CSS 基本功.这是前置条件. 2. 通读官方教程 (guide) 的基础篇.不要用任何构建工具,就只用最简单的 <script> ...

随机推荐

  1. Android之APP模块编译

    一,如何把app编进系统 a.源码编译,在packages/apps目录下有安卓原生的app,以Bluetooth为例,源码根目录下有Android.mk文件: packages\apps\Bluet ...

  2. 浏览器加载显示html页面内容的顺序

    我们经常看到浏览器在加载某个页面时,部分内容先显示出来,又有些内容后显示.那么浏览器加载显示html究竟是按什么顺序进行的呢 其实浏览器加载显示html的顺序是按下面的顺序进行的:1.IE下载的顺序是 ...

  3. MSG结构体

    typedef struct tagMSG { // msg HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; PO ...

  4. sublime text 3中修改tab键为缩进4个空格

    1. 菜单栏里点击 Preferences-> Setting-User, 如图 2. 在弹出来的文本里,添加如下两行: { // 注意只有一个大括号,如果之前有属性,如在之前的属性后确保有 , ...

  5. windows下patch

    经常在网上看到有人发布patch文件来更新他们的开源代码,例如cegui.ogre等都使用这种形式来修bug或者增加一些小功能.但是,我们下载到的patch文件,貌似是linux/unix的diff工 ...

  6. liteos内存(三)

    1. 概述 1.1 基本概念 内存管理模块管理系统的内存资源,它是操作系统的核心模块之一.主要包括内存的初始化.分配以及释放. 在系统运行过程中,内存管理模块通过对内存的申请/释放操作,来管理用户和O ...

  7. 洛谷 - P1355 - 神秘大三角 - 简单计算几何

    https://www.luogu.org/problemnew/show/P1355 判断一个点和三角形的位置关系,最简单的思路就是用向量. 首先排除掉和三角形顶点重合的情况. 把三角形设计成一个首 ...

  8. NOJ2026:Keroro侵略地球(01字典树)

    传送门 题意 略 分析 将n个数插入字典树中,m次查询,取最大值,复杂度\(O(mlogn)\) trick 1.注意题目给的空间,开40刚刚够(62852K) 2.作为01字典树的模板保存了 代码 ...

  9. HDU5145:5145 ( NPY and girls ) (莫队算法+排列组合+逆元)

    传送门 题意 给出n个数,m次访问,每次询问[L,R]的数有多少种排列 分析 \(n,m<=30000\),我们采用莫队算法,关键在于区间如何\(O(1)\)转移,由排列组合知识得到,如果加入一 ...

  10. php,c# hamsha1

    #!/usr/bin/php <?php print strtoupper(hash_hmac("sha256", "message", "ke ...