Nginx学习笔记--001-Nginx快速搭建

时间:2021-08-09 15:04:51

Nginx ("engine x") 是一个高性能的HTTP反向代理服务器,也是一个IMAP/POP3/SMTP服务器。Nginx是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。关于Nginx的优点,我在这里就不讨论了,网上的资料多的是。

如何使用Nginx快速搭建一个高性能的网站?

1.首先去Nginx官网下载一个最新版本的Nginx,下载地址:http://nginx.org/en/download.html。我这里下载的版本是:nginx/Windows-1.11.6。下载完成之后,得到一个.zip的压缩包,把压缩包解压到D盘根目录。如图1-1

Nginx学习笔记--001-Nginx快速搭建

图1-1

2.修改配置文件。打开“conf”文件夹下的“nginx.conf”文件。其中修改的主要部分见图1-2。

Nginx学习笔记--001-Nginx快速搭建

图1-2

下面是我修改后的完整配置文件信息:

#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;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #长连接超时时间,单位是秒 #gzip on; #启用Gizp压缩 #服务器的集群
upstream rj.nginx.com { #服务器集群名字
server 127.0.0.1:8001 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
server 127.0.0.1:8002 weight=2;
} #当前的Nginx的配置
server {
listen 80; #监听80端口,可以改成其他端口
server_name localhost; # 当前服务的域名 #charset koi8-r; #access_log logs/host.access.log main; location / {
proxy_pass http://rj.nginx.com;
proxy_redirect default;
}
location ~ \.(jpg|png|jpeg|bmp|gif|swf|css)$
{ expires 30d;
root /nginx-1.4.7;#root:
break;
} #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;
# }
#} }

3.打开命令行,定位到Nginx当前目录,使用“start nginx”命令启动nginx。如图1-3

Nginx学习笔记--001-Nginx快速搭建

图1-3

4.打开浏览器,输入:http://localhost/。可以发现,浏览的网站,会在两个站点见不停的切换,并且站点2的使用几率会稍高一些,因为站点2的权重设置的比站点1的大。如图1-4

Nginx学习笔记--001-Nginx快速搭建Nginx学习笔记--001-Nginx快速搭建Nginx学习笔记--001-Nginx快速搭建

Nginx学习笔记--001-Nginx快速搭建的更多相关文章

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

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

  2. Nginx学习笔记(反向代理&搭建集群)

    一.前言 1.1 大型互联网架构演变历程 1.1.1 淘宝技术 淘宝的核心技术(国内乃至国际的 Top,这还是2011年的数据) 拥有全国最大的分布式 Hadoop 集群(云梯,2000左右节点,24 ...

  3. nginx 学习笔记(1) nginx安装

    1.nginx安装 根据操作系统的不同,nginx的安装方式也不相同. 1.1 对linux系统来说,nginx.org提供了nginx安装包.http://nginx.org/en/linux_pa ...

  4. Nginx学习笔记六Nginx的模块开发

    1.Nginx配置文件主要组成:main(全局配置)这部分的指令将影响其他所有部分.server(虚拟主机配置)这部分指令主要用于指定虚拟主机域名,IP和端口.upstream(主要为反向代理,负载均 ...

  5. 七、Nginx学习笔记七Nginx的Web缓存服务

    user www; worker_processes 1; error_log /usr/local/nginx/logs/error.log crit; pid /usr/local/nginx/l ...

  6. nginx学习笔记(7)Nginx如何处理一个请求---转载

    如何防止处理未定义主机名的请求基于域名和IP混合的虚拟主机一个简单PHP站点配置 基于名字的虚拟主机 Nginx首先选定由哪一个虚拟主机来处理请求.让我们从一个简单的配置(其中全部3个虚拟主机都在端口 ...

  7. nginx 学习笔记(5) nginx调试日志

    为启动一个调试日志,nginx需要在构建时配置城支持调试模式. ./configure --with-debug ... 而且调试级别应该使用err_log指令来设置: err_log /path/t ...

  8. nginx 学习笔记(3) nginx管理

    nginx可以通过向其发送信号来进行管理.默认情况下主进程的进程ID写到文件/usr/local/nginx/logs/nginx.pid中.当然也可以在配置文件中自定义该pid文件,自定义使用pid ...

  9. nginx 学习笔记(6) nginx配置文件中的度量单位

    容量大小可以用比特(byte),千比特(kilobyte,后缀k或者K)或者兆(megabytes,后缀m或者M),例如:“1024”,“8k”,“1m”. 时间间隔可以用毫秒(millisecond ...

  10. Nginx学习笔记~目录索引

    回到占占推荐博客索引 前几天整理了<Docker的学习笔记索引>,受到了很多朋友的关注,今天把Nginx的文章也整理一下,以后将永久更新,像大叔之前的<EF文章系列>,< ...

随机推荐

  1. Apache Commons CLI官方文档翻译 —— 快速构建命令行启动模式

    昨天通过几个小程序以及Hangout源码学习了CLI的基本使用,今天就来尝试翻译一下CLI的官方使用手册. 下面将会通过几个部分简单的介绍CLI在应用中的使用场景. 昨天已经联系过几个基本的命令行参数 ...

  2. storm环境搭建

    备注——使用: 1.单机版本: 启动zkServer.nimbus.supervisor.ui服务: zkServer.sh start zkServer.sh status #查看zkserver是 ...

  3. c&num;怎么获取当前页面的url

    Request.ApplicationPath: /testwebRequest.CurrentExecutionFilePath: /testweb/default.aspxRequest.File ...

  4. groupinfo

    http://www.wenzizone.com/2011/07/07/centos_x64_yum_da_jian_xen.html [yum xen] 配置epel就不说了,ruiy哥的文档有; ...

  5. 转:DSP学习经验

    转载:http://www.cnblogs.com/MrYang/archive/2010/12/21/1913035.html

  6. 2017年Web前端开发工程师薪资越来越高?

    放眼全球,不仅在国内的互联网行业,在国外,前端工程师一样是需求旺盛.供不应求的香饽饽.所以在供不应求的前端招聘市场上,优秀的前端工程师才是有话语权的那一方. 前端开发是做什么的? 前端是互联网时代软件 ...

  7. UIGraphicsBeginImageContext - 位图上下文

    UIGraphicsBeginImageContext 首先,先来认识一个UIGraphicsBeginImageContext,它会创建一个基于位图的上下文(context)(默认创建一个透明的位图 ...

  8. jsp &lpar;2&rpar;

    一.内置对象: 二.如何在代码中使用js代码: <script type="text/javascript" src="js的路径名"></s ...

  9. mysql-sql-standard

    https://github.com/zhishutech/mysql-sql-standard

  10. 擦亮自己的眼睛去看SQLServer之谈谈锁机制

    http://www.cnblogs.com/yueyue_jwfm/category/292724.html