nginx 新手入门
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 新手入门的更多相关文章
- nginx新手入门
nginx的应用 官网(nginx.org) nginx可以做1.web服务(http服务)2.http代理服务3负载均衡在官网(nginx.org)如下图处下载先点击 跳转下一页点击(nginx/w ...
- nginx 学习笔记(2) nginx新手入门
这篇手册简单介绍了nginx,并提供了一些可以操作的简单的工作.前提是nginx已经被安装到你的服务器上.如果没有安装,请阅读上篇:nginx 学习笔记(1) nginx安装.这篇手册主要内容:1. ...
- 即时通讯新手入门:一文读懂什么是Nginx?它能否实现IM的负载均衡?
本文引用了“蔷薇Nina”的“Nginx 相关介绍(Nginx是什么?能干嘛?)”一文部分内容,感谢作者的无私分享. 1.引言 Nginx(及其衍生产品)是目前被大量使用的服务端反向代理和负载均衡 ...
- nginx配置入门
谢谢作者的分享精神,原文地址:http://www.nginx.cn/591.html nginx配置入门 之前的nginx配置是对nginx配置文件的具体含义进行讲解,不过对于nginx的新手可能一 ...
- nginx 配置入门
之前的nginx配置是对nginx配置文件的具体含义进行讲解,不过对于nginx的新手可能一头雾水. 今天看到个文档不错,翻译过来分享给大家,可以让新手更详细地了解nginx配置,可以说是nginx配 ...
- Docker新手入门:基本用法
Docker新手入门:基本用法 1.Docker简介 1.1 第一本Docker书 工作中不断碰到Docker,今天终于算是正式开始学习了.在挑选系统学习Docker以及虚拟化技术的书籍时还碰到了不少 ...
- 《IM开发新手入门一篇就够:从零开发移动端IM》
登录 立即注册 TCP/IP详解 资讯 动态 社区 技术精选 首页 即时通讯网›专项技术区›IM开发新手入门一篇就够:从零开发移动端IM 帖子 打赏 分享 发表评论162 想开 ...
- 【代理是什么?】nginx快速入门+反向代理hexo个人博客
@ 目录 前言 本文说明 请大家务必查看 工作原理 正向代理 反向代理 环境准备 详细版 入门:搭建步骤 配置阿里云epel源: yum安装nginx: 启动nginx: 配置default.conf ...
- 新手入门指导:Vue 2.0 的建议学习顺序
起步 1. 扎实的 JavaScript / HTML / CSS 基本功.这是前置条件. 2. 通读官方教程 (guide) 的基础篇.不要用任何构建工具,就只用最简单的 <script> ...
随机推荐
- VMware ESXI虚拟机挂载移动硬盘
Windows server2008 R2 1.“编辑虚拟机设置”,点击“添加” 2.点击添加“USB控制器”: 3.添加完“USB控制器”以后,再点击添加“USB设备”: 完成即可:如果系统里面不显 ...
- linux中用无名管道进行文件的读写
1管道是什么: 水管子大家知道,有两端,在此一端用来读一端用来写,其中一端的输出作为另外一端的输入. 2 函数原型 int pipe(int pipefd[2]);//参数中分别代表的两端 3 例子: ...
- 任务31:课时介绍 & 任务32:Cookie-based认证介绍 &任务33:34课 :AccountController复制过来没有移除[Authorize]标签
任务31:课时介绍 cookie-based网站这边的认证 jwt基于移动端和前后端分离的项目,jwt有一些独特的优势 jwt在asp.net core中的实现机制,了解实现机制并进行扩展.比如非标准 ...
- iView 实战系列教程(21课时)_1.iView 实战教程之配置篇
1.iView 实战教程之配置篇 点击添加插件,. 选中后安装 全部导入还是按需导入. 2.是否需要自定义主题变量 3.多语言的设置. 这里我们全部选择为默认 然后点击继续. 启动项目 入口文件导入了 ...
- Spherical Harmonics Lighting
[转自:http://www.cnblogs.com/daniagger/archive/2012/05/29/2524133.html] 1.背景知识 1.1 光照表示 之前我们都只考虑光源点和物体 ...
- SCUT - 244 - 全新的游戏 - 凸包
https://scut.online/p/244 除了常规的求凸包求面积,还有一个判断点在凸包内,先找出点所在的三角扇区. #include<bits/stdc++.h> using n ...
- springcloud(一) 服务拆分
一般我们的项目如果需要从单应用服务升级到微服务,必须要将原来的服务做拆分,我这边的拆分也是基于将之前spb-demo的springboot单应用做拆分,拆分出三个应用,spb-brian-query- ...
- java中多线程的两种创建方式
一丶继承Thread类实现多线程 第一步:继承Thread类第二步:重写run()方法第三步:创建继承了Thread类的对象 , 调用start()方法启动. //线程创建方式一 : /* 第一步:继 ...
- python之unittest
unittest是单元测试的一个框架 在说unittest之前,先说几个概念: TestCase 也就是测试用例 TestSuite 多个测试用例集合在一起,就是TestSuite TestLoade ...
- AtCoder Grand Contest 016 E - Poor Turkeys
题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_e 题目大意: 有\(N\)只火鸡,现有\(M\)个人,每个人指定了两只火鸡\(x,y\),每 ...