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> ...
随机推荐
- 51Nod 1327 棋盘游戏 —— 延迟DP
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1327 看博客:https://www.cnblogs.com/Na ...
- JS获取子节点、父节点和兄弟节点的方法实例总结
转自:https://www.jb51.net/article/143286.htm 本文实例讲述了JS获取子节点.父节点和兄弟节点的方法.分享给大家供大家参考,具体如下: 一.js获取子节点的方式 ...
- SpringBoot启动的时候不去校验数据库连接配置是否正确
spring boot在启动的时候只会检查你是否配置了数据库连接, 而不会检测配置的是否正确 这样会出现的问题是: 只有在你使用数据库的时候才知道配置出错, 我们希望是在程序启动的时候就进行检查, 如 ...
- HDU 1270 小希的数表 (暴力枚举+数学)
题意:... 析:我们可以知道,a1+a2=b1,那么我们可以枚举a1,那么a2就有了,并且a1+a3=b2,所以a3就有了,我们再从把里面的剩下的数两两相加,并从b数组中去掉, 那么剩下的最小的就是 ...
- Android 布局之GridLayout(转载)
转载:http://www.cnblogs.com/skywang12345/p/3154150.html 1 GridLayout简介 GridLayout是Android4.0新提供的网格矩阵形式 ...
- JAVA基础--JAVA API常见对象(字符串&缓冲区)11
一. String 类型 1. String类引入 第二天学习过Java中的常量: 常量的分类: 数值型常量:整数,小数(浮点数) 字符型常量:使用单引号引用的数据 字符串常量:使用双引号引用 ...
- Hibernate中表与表之间的关联多对多,级联保存,级联删除
第一步:创建两个实体类:用户和角色实体类,多对多关系,并让两个实体类之间互相关联: 用户实体类: package com.yinfu.entity; import java.util.HashSet; ...
- 51Nod 1174 区间中最大的数(RMQ)
#include <iostream> #include <algorithm> #include <cstring> using namespace std; + ...
- April Fools Contest 2017 F
Description You are developing a new feature for the website which sells airline tickets: being able ...
- sql 语句操作,修改字段中字符串的一部分
update 表名 set 字段=replace(字段,‘替换的部分’,‘替换后的字符串’): update 表名 set A=replace( A, '海淀', '朝阳') where A like ...