Nginx学习(个人笔记)
zhezhongyun 2025-01-03 20:44 28 浏览
一、Nginx安装
- 安装
安装地址:http://nginx.org/en/download.html
我选择的是windows安装,下载成功后解压并安装,可以看到以下文件:
注意:安装目录不要有中文,否则会报错。
- 启动
建议用cmd打开,直接双击nginx.exe会出现一闪而过的画面。进入到安装目录下:
start nginx
这时候到浏览器访问localhost:80端口(或者直接访问localhost,http默认协议为http,默认端口为80),就可以看见以下页面:
二、Nginx常用命令
start nginx —— 启动
nginx -s stop —— 停止
nginx -s quit —— 安全退出
nginx -s reload —— 重新加载配置文件 (一般修改配置文件之后就要执行此命令)
三、nginx.conf配置文件
1.全局块:
主要设置一些影响nginx 服务器整体运行的配置指令。如:用户(组),生成worker process 数,日志存放路径,配置文件引入,pid文件路径
2.events 块
影响nginx 服务器与用户的网络连接。如:每个worker processs 的最大连接数,事件驱动模型
3.http块
nginx 配置中的重要部分,代理,缓存等功能都可以在此配置。如:文件引入,mime-type 定义,连接超时,单连接请求数上限
3.1 .server 块
与“虚拟主机”的概念有密切关系。每个server 块相当于一台虚拟主机,最常见的两个配置项是监听配置和虚拟主机的名称或IP配置
3.1.1 .location 块
在server 块中,可以有多个。地址定向,数据缓存,和应答控制等功能都是在这部分实现。
详细配置:
# =========================全局块============================
# user user [grop]; # 指定可以运行nginx 服务器的用户及组。只被设置的用户及组才有权限管理
# user nobody nobody; # 所用用户可用,默认配置
user nginx nginx;
# worker_processes number | auto; # 控制并发处理,值越大,支持的并发数越多
# worker_processes 1; # 默认值 ,最多产生1个worker_processes
worker_processes auto;
# pid file; # pid 存放路径.相对或绝对路径
# pid logs/nginx.pid; # 默认在安装目录logs/nginx.pid
pid /var/run/nginx.pid;
# error_log file | stder [debug | info | notice | warn | error | crit | alert | emerg]; #错误日志存放路径
# error_log logs/error.log error; # 可在 全局块,http 块 ,serveer 块,location 块中配置
error_log /data/wwwlogs/error_nginx.log crit;
# include file; # 配置文件引入,可以是相对/绝对路径。指令可以放在配置文件的任意地方(任意块中)
worker_rlimit_nofile 51200;
# ===========================events 块===============================
events {
#accept_mutex on|off; # 网络连接序列化。解决“惊群”问题
accept_mutex on; # 默认为开启状态
#multi_accept on|off; # 是否允许worker process同时接收多个网络连接,
multi_accept off; # 默认为关闭
#use method; # 事件驱动模型选择,select 、 poll 、 kqueue 、 epoll 、 rtsig 、 /dev/poll 、 eventport
use epoll;
#worker_connections number; # worker process 的最大连接数。
worker_connections 512; # 默认值为512。注意设置不能大于操作系统支持打开的最大文件句柄数量。
}
# ==========================http块============================
http {
# 定义 mime-type (网络资源的媒体类型)。 指定能识别前端请求的资源类型
include mime.types; # 引入外部文件 ,在外部文件中有定义types 块
default_type application/octet-stream; # 默认为 text/plain 。 http块、server块、location块中可配置
# access_log path [format[buffer=size]]; # 定义服务日志,记录前端的请求日志
# access_log logs/access.log combined; # combined 是默认定义的日志格式字符串名称
access_log off; # 关闭日志
# log_format name stirng # 定义了日志格式,以便access_log 使用
# log_format combined '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
# sendfile on|off; # 配置允许 sendfile 方式传输文件
sendfile off; # 默认关闭,可在http块、server块、location块 中定义
# sendfile_max_chunk size; # 配置worker process 每次调用sendfile()传输的数据最最大值
# sendfile_max_chunk 0; # 默认为0 不限制。 可在http块、server块、location块 中定义
sendfile_max_chunk 128k;
# keepalive_timeout timeout [header_timeout]; # 配置连接超时时间, 可在http块、server块、location块 中定义
# keepalive_timeout 75s; # 默认为75秒,与用户建立会话连接后,nginx 服务器可以保持这些连接打开的时间。
keepalive_timeout 120 100s; # 在服务器端保持连接的时间设置为120s,发给用户端的应答报文头部中keep-alive 域的设置为100s
# keepalive_requests number; # 单连接请求数上限
keepalive_requests 100; # 默认为 100
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 1024m;
tcp_nopush on;
server_tokens off;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#Gzip Compression
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
######################## default ############################
# server {
# listen 8067;
# server_name _;
# access_log /data/wwwlogs/access_nginx.log combined;
# root /data/wwwroot/default;
# index index.html index.htm index.jsp;
# location /nginx_status {
# stub_status on;
# access_log off;
# allow 127.0.0.1;
# deny all;
# }
# location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
# expires 30d;
# access_log off;
# }
# location ~ .*\.(js|css)?$ {
# expires 7d;
# access_log off;
# }
# location ~ {
# proxy_pass http://127.0.0.1:8080;
# include proxy.conf;
# }
# }
# server{
# listen 8087;
# server_name _;
# root /home/wwwroot/default;
# location / {
# }
# }
upstream backend{
server 127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=2;
server 139.224.209.104:8080 backup;
}
server{
listen 80;
listen 443 ssl;
server_name wmcenter.xy-asia.com;
#ssl on;
default_type 'text/html';
charset utf-8;
ssl_certificate /usr/local/cert/1634560_wmcenter.xy-asia.com.pem;
ssl_certificate_key /usr/local/cert/1634560_wmcenter.xy-asia.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
root html;
index index.html index.htm;
location ~ .*\.(js|css)?$
{
expires 1h;
proxy_pass http://backend;
}
location / {
proxy_pass http://backend;
add_header backendIP $upstream_addr;
# proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto https;
# proxy_redirect http://http://127.0.0.1:8080 $scheme://127.0.0.1:8080;
# port_in_redirect on;
# proxy_redirect off;
include proxy.conf;
}
# error_log /home/wwwlogs/xywm.log;
}
# 缓存配置
proxy_temp_file_write_size 264k;
proxy_temp_path /data/wwwlogs/nginx_temp;
proxy_cache_path /data/wwwlogs/nginx_cache levels=1:2 keys_zone=prc:200m inactive=5d max_size=400m;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
########################## vhost #############################
include vhost/*.conf;
}
四、部署vue项目到开发环境
- npm run build 打包文件,默认输出为dist;
- 将dist文件夹复制到nginx下面的html目录里面(dist可重命名);
- 修改配置文件:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dist; // vue打包的文件所在的目录
index index.html index.htm;
// try_files防止404,$uri表示当前路径,从前往后匹配,一直到/index.html
try_files $uri $uri/ /index.html;
}
}
- 重启nginx,在cmd输入nginx -s reload
相关推荐
- 激光手术矫正视力对眼睛到底有没有伤害?
-
因为大家询问到很多关于“基质不能完全愈合”的问题,有必要在这里再详细解释一下。谢谢@珍惜年少时光提出的疑问:因为手头刚好在看组织学,其中提到:”角膜基质约占角膜的全厚度的90%,主要成分是胶原板层,...
- OneCode核心概念解析——View(视图)
-
什么是视图?在前面的章节中介绍过,Page相关的概念,Page是用户交互的入口,具有Url唯一性。但Page还只是一个抽象的容器,而View则是一个具备了具体业务能力的特殊的Page,它可以是一个...
- 精品博文图文详解Xilinx ISE14.7 安装教程
-
在软件安装之前,得准备好软件安装包,可从Xilinx官网上下载:http://china.xilinx.com/support/download/index.html/content/xilinx/z...
- 卡片项目管理(Web)(卡片设计的流程)
-
简洁的HTML文档卡片管理,简单框架个人本地离线使用。将个人工具类的文档整理使用。优化方向:添加图片、瀑布式布局、颜色修改、毛玻璃效果等。<!DOCTYPEhtml><html...
- GolangWeb框架Iris项目实战-JWT和中间件(Middleware)的使用EP07
-
前文再续,上一回我们完成了用户的登录逻辑,将之前用户管理模块中添加的用户账号进行账号和密码的校验,过程中使用图形验证码强制进行人机交互,防止账号的密码被暴力破解。本回我们需要为登录成功的用户生成Tok...
- sitemap 网站地图是什么格式?有什么好处?
-
sitemap网站地图方便搜索引擎发现和爬取网页站点地图是一种xml文件,或者是txt,是将网站的所有网址列在这个文件中,为了方便搜索引擎发现并收录的。sitemap网站地图分两种:用于用户导...
- 如何在HarmonyOS NEXT中处理页面间的数据传递?
-
大家好,前两天的Mate70的发布,让人热血沸腾啊,不想错过,自学的小伙伴一起啊,今天分享的学习笔记是关于页面间数据伟递的问题,在HarmonyOSNEXT5.0中,页面间的数据传递可以有很多种...
- 从 Element UI 源码的构建流程来看前端 UI 库设计
-
作者:前端森林转发链接:https://mp.weixin.qq.com/s/ziDMLDJcvx07aM6xoEyWHQ引言由于业务需要,近期团队要搞一套自己的UI组件库,框架方面还是Vue。而业界...
- jq+ajax+bootstrap改了一个动态分页的表格
-
最近在维护一个很古老的项目,里面是用jq的dataTable方法实现一个分页的表格,不过这些表格的分页是本地分页。现在想要的是点击分页去请求数据。经过多次的修改,以失败告终。分页的不准确,还会有这个错...
- 学习ES6- 入门Vue(大量源代码及笔记,带你起飞)
-
ES6学习网站:https://es6.ruanyifeng.com/箭头函数普通函数//普通函数this指向调用时所在的对象(可变)letfn=functionfn(a,b){...
- 青锋微服务架构之-Ant Design Pro 基本配置
-
青锋(msxy)-Gitee.com1、更换AntDesignPro的logo和名称需要修改文件所在位置:/config/defaultSetting.jsconstproSett...
- 大数据调度服务监控平台(大数据调度服务监控平台官网)
-
简介SmartKettle是针对上述企业的痛点,对kettle的使用做了一些包装、优化,使其在web端也能具备基础的kettle作业、转换的配置、调度、监控,能在很大一定程度上协助企业完成不同...
- Flask博客实战 - 实现博客首页视图及样式
-
本套教程是一个Flask实战类教程,html/css/javascript等相关技术栈不会过多的去详细解释,那么就需要各位初学者尽可能的先去掌握这些基础知识,当然本套教程不需要你对其非常精通,但最起码...
- Web自动化测试:模拟鼠标操作(ActionChains)
-
在日常的测试中,经常会遇到需要鼠标去操作的一些事情,比如说悬浮菜单、拖动验证码等,这一节我们来学习如何使用webdriver模拟鼠标的操作首页模拟鼠标的操作要首先引入ActionChains的包fro...
- DCS F-16C 中文指南 16.9ILS仪表降落系统教程
-
10–ILS教程我们的ILS(仪表着陆进近)将到达Batumi巴统机场。ILS频率:110.30跑道航向:120磁航向/126真航向无线电塔频率:131.0001.设置雷达高度表开关打开(前)并...
- 一周热门
- 最近发表
- 标签列表
-
- HTML 教程 (33)
- HTML 简介 (35)
- HTML 实例/测验 (32)
- HTML 测验 (32)
- JavaScript 和 HTML DOM 参考手册 (32)
- HTML 拓展阅读 (30)
- HTML常用标签 (29)
- HTML文本框样式 (31)
- HTML滚动条样式 (34)
- HTML5 浏览器支持 (33)
- HTML5 新元素 (33)
- HTML5 WebSocket (30)
- HTML5 代码规范 (32)
- HTML5 标签 (717)
- HTML5 标签 (已废弃) (75)
- HTML5电子书 (32)
- HTML5开发工具 (34)
- HTML5小游戏源码 (34)
- HTML5模板下载 (30)
- HTTP 状态消息 (33)
- HTTP 方法:GET 对比 POST (33)
- 键盘快捷键 (35)
- 标签 (226)
- HTML button formtarget 属性 (30)
- CSS 水平对齐 (Horizontal Align) (30)