nginx: download(推荐)
解压后,我们得到这样一个目录(注意不要解压到中文路径的目录):
重点:
1.conf目录下的nginx.conf文件是nginx的配置文件,启动前我们需要先修改好我们需要的配置。
2.html目录存放的时候我们的网页文件。如下:
3.nginx的所有命令必须在这个根目录下执行在有效(有nginx.exe的目录)。
nginx.conf:
events {
worker_connections 1024;
}
http {
server {
# ������Ķ˿�
listen 8880;
# ����ʱ�ĵ�ַ
server_name localhost;
# ������ַ������: localhost:8880, Ĭ�ϻ���html�ļ������� index.html�ļ�
location / {
root html;
index index.html;
}
# 404ҳ�����ã�ҳ��ͬ����html�ļ�����
error_page 404 /404.html;
location = /404.html {
root html;
}
# ����������ҳ������
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# ���ô�����������Ŀ���ڱ����ģ������ǵ�request��Ҫ��������ip��ַ��������request����Ϊlocalhost:8880/api/login?name=12345,��ô������ľ���location /api,���ջ������ http://192.168.0.0:80/api/login?name=12345
location /api {
proxy_pass https://test.meke.io/api/v1; #http://192.168.0.0:80;
}
# һ��ǰ�˲�����vue������react�ȿ�ܣ�Ĭ�϶��ǵ�ҳ��ģ���������Ŀ�Ƕ�ҳ��ģ�����Ҫ�õ���������á�
# ��Ϊ��ʱ����������url����localhost:8880/#/login,���� localhost:8880/a.html/#/login
# ����������Ҫ��·����a.htmlָ������html�ļ����е��ļ�����ΪĬ����index.html
location /a.html {
alias html;
index a.html;
}
location /b.html{
alias html;
index b.html;
}
}
}
乱码的是我的中文说明。
server_name后面的localhost是访问的地址,listen后面的8880是访问时的端口。
保存好配置文件后,我们可以执行一下启动命令。
启动后访问地址:localhost:8880
启动命令:
start nginx
重启命令,重新载入配置文件:
修改配置后,我们需要重启nginx才能使新的配置生效。
nginx -s reload
关闭命令:
nginx -s stop 或者 nginx -s quit
stop表示立即停止nginx,不保存相关信息
quit表示正常退出nginx,并保存相关信息
查看错误命令,查看nginx状态(重要):
如果启动后,发现没有配置没有用,可能是报错了,可以运行以下命令查看报错原因。
nginx -t
查看版本命令:
nginx -v
nginx.conf基本配置有哪些?
events {
worker_connections 1024;
}
#图片文件结尾的走文件服务器,动态页面走web服务器
server {
# 启动后的端口
listen 8880;
# 启动时的地址
server_name localhost;
# 启动后,地址栏输入: localhost:8880, 默认会在html文件夹下找 index.html文件
location / { #location后面的“/”代表匹配的路由页面。
root html; #根目录,索引的文件夹
index index.html; #默认进入的页面。
}
# 404页面配置,页面同样在html文件夹中
error_page 404 /404.html;
location = /404.html {
root html;
}
# 其他错误码页面配置
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 配置代理。由于项目是在本地起动的,而我们的request需要请求其他ip地址。如果你的request链接为localhost:8880/api/login?name=12345,那么下面配的就是location /api,最终会代理到 http://192.168.0.0:80/api/login?name=12345
location /api {
proxy_pass http://192.168.0.0:80; #跨域代理
}
# 一把前端不管用vue,还是react等框架,默认都是单页面的,如果你的项目是多页面的,则需要用到下面的配置。
# 因为此时你的浏览器的url不是localhost:8880/#/login,而是 localhost:8880/a.html/#/login
# 所以我们需要将路径中a.html指向具体的html文件夹中的文件,因为默认是index.html
location /a.html {
alias html;
index a.html;
}
location /b.html{
alias html;
index b.html;
}
}
#定义 Nginx 运行的用户和用户组,默认由 nobody 账号运行, windows 下面可以注释掉。
user nobody;
#nginx进程数,建议设置为等于CPU总核心数。可以和worker_cpu_affinity配合
worker_processes 1;
#全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#进程文件,window下可以注释掉
#pid logs/nginx.pid;
# 一个nginx进程打开的最多文件描述符(句柄)数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,
# 但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。
worker_rlimit_nofile 65535;
#工作模式与连接数上限
events {
# 参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
# epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。
#use epoll;
#connections 20000; # 每个进程允许的最多连接数
# 单个进程最大连接数(最大连接数=连接数*进程数)该值受系统进程最大打开文件数限制,需要使用命令ulimit -n 查看当前设置
worker_connections 65535;
}
#设定http服务器
http {
#文件扩展名与文件类型映射表
#include 是个主模块指令,可以将配置文件拆分并引用,可以减少主配置文件的复杂度
include mime.types;
#默认文件类型
default_type application/octet-stream;
#charset utf-8; #默认编码
#定义虚拟主机日志的格式
#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指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
sendfile on;
#autoindex on; #开启目录列表访问,合适下载服务器,默认关闭。
#防止网络阻塞
#tcp_nopush on;
#长连接超时时间,单位是秒,默认为0
keepalive_timeout 65;
# gzip压缩功能设置
gzip on; #开启gzip压缩输出
gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
gzip_comp_level 6; #压缩等级
#压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on; //和http头有关系,加个vary头,给代理服务器用的,有的浏览器支持压缩,有的不支持,所以避免浪费不支持的也压缩,所以根据客户端的HTTP头来判断,是否需要压缩
#limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用
# http_proxy服务全局设置
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 75;
proxy_send_timeout 75;
proxy_read_timeout 75;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /usr/local/nginx/proxy_temp 1 2;
# 设定负载均衡后台服务器列表
upstream backend.com {
#ip_hash; # 指定支持的调度算法
# upstream 的负载均衡,weight 是权重,可以根据机器配置定义权重。weigth 参数表示权值,权值越高被分配到的几率越大。
server 192.168.10.100:8080 max_fails=2 fail_timeout=30s ;
server 192.168.10.101:8080 max_fails=2 fail_timeout=30s ;
}
#虚拟主机的配置
server {
#监听端口
listen 80;
#域名可以有多个,用空格隔开
server_name localhost fontend.com;
# Server Side Include,通常称为服务器端嵌入
#ssi on;
#默认编码
#charset utf-8;
#定义本虚拟主机的访问日志
#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;
}
# 图片缓存时间设置
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 10d;
}
# JS和CSS缓存时间设置
location ~ .*.(js|css)?$ {
expires 1h;
}
#代理配置
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#location /proxy/ {
# 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的很多配置都可以在网上百度的,如果需要深度学习,推荐文章:
文章浏览阅读712次。视频播放器原理 什么是ffmpeg? ffmpeg 音视频编/解码 流程图 ffmpeg 常用 struct AVFormatContext AVStream AVCodecContext AVCodec AVPacket AVFrame ffmpeg 常用Api av_register_all() avformat_alloc_output_context2() avio_open()..._视频效果演示系统的核心技术
文章浏览阅读449次。Java List集合多种情况处理方法:List集合交集、并集、差集、去重、与数组互转、删除、排序等操作_java list reduce
文章浏览阅读2.3k次,点赞77次,收藏80次。需求:指人对客观事务需要的表现,体现为愿望、意向和兴趣,因而成为行动的一种直接原因。软件需求(IEEE软件工程标准词汇表):(1)用户解决问题或达到目标所需的条件或能力。(2)系统或系统部件要满足合同、标准、规范或者其他正式规定文档所需具有条 件或能力。(3)对(1)或(2)中的一个条件或一种能力的一种文档化表述。用例:定义 1 用例是对一个活动者使用一个系统的一项功能时进行交互过程中的一个文字描述序列。_uml需求文档访客管家
文章浏览阅读574次。第三章、Linux根文件系统及文件管理命令详解02_03_Linux根文件系统详解文件系统:rootfs: 根文件系统 FHS:Filesystem Hierarchy Standard(文件系统目录标准)的缩写,多数Linux版本采用这种文件组织形式,类似于Windows操作系统中c盘的文件目录,FHS采用树形结构组织文件。FHS定_根文件系统文本登陆
文章浏览阅读358次。马克 · 扎克伯格期望的元宇宙到底会是什么样子?_马克扎克伯格博客
文章浏览阅读1.4w次,点赞8次,收藏78次。本文接上一篇文章 使用Python开发游戏运行脚本(一)成功调用大漠插件上一篇我们已经简单实现了python调用大漠插件并输出版本号的功能,接下来我们要做的就是通过大漠插件模拟鼠标点击和键盘文字输入。 由于近年来最热门的游戏基本都是手游,所以我们也会以手游为例来进行游戏脚本的开发。大漠插件是一款针对Windows平台的鼠标键盘模拟+图文查找库,这样我们要想实现手游脚本开发的第一步,就是下载Android模拟器,然后在对安卓模拟器进行鼠标和键盘的模拟,以此来实现自动化游戏脚本。一、Android模拟器的_大漠窗口绑定成功按键
文章浏览阅读1k次。 利用Canvas的fillText(),隔一定时间在画布上作画<!DOCTYPE html><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> &_canvas画字符雨
文章浏览阅读1.1k次。微信公众号跳转微信小程序,自定义微信跳转标签_opentaglist
文章浏览阅读4.3k次。数据恢复技术与LVM数据恢复方法 1摘要 随着计算机网络应用的发展,数据存储的安全性变的越来越重要。在常见的基于RAID和LVM的环境下面,当出现硬盘故障或者错误操作导致数据丢失的情况下,采用适当的数据恢复策略可以在很大程度上提供数据恢复的成功概率。本文研究了几种情况下的数据恢复技术和方法,为数据恢复和数据安全的预防提供了指导。 2数据恢复需求 2.1Linux IO存储栈 图(1)Linux IO 存储..._vgreduce --removemissing恢复
文章浏览阅读307次。深度学习程序员想年薪百万,基础必须打牢,所以推荐重点书籍Deep Learning花书Deep Learning with PythonDeep Learning for Computer Vision with PythonScikit-Learn与TensorFLow机器学习实用指南深度学习实践Tensorflow机器学习指南..._年薪百万的程序员看什么书
文章浏览阅读1.3k次。一、使用clock()函数,获取毫秒级(ms)时间[1]#include <time.h>//clock()头文件clock_t start = clock();{statement section}//测试代码段clock_t end = clock();printf("the running time is :%fs\n", (double)(end -s..._large_integer nfreq, t1, t2;
文章浏览阅读6.8k次,点赞3次,收藏31次。 前言: 至于用哪个开发工具本文暂且不做任何讨论, 今天着重讲解IntelliJ IDEA这款开发工具的使用 前言:IntelliJ IDEA如果说IntelliJ IDEA是一款现代化智能开发工具的话,Eclipse则称得上是石器时代的东西了。其实笔者也是一枚从Eclipse转IDEA的探索者,随着近期的不断开发实践和调试,逐步..._idea使用视频教程