Nginx是什么?

Nginx是什么?
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器 ,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的,因它的稳定性、丰富的功能集、简单的配置文件和低系统资源的消耗而闻名。
优点
速度更快、并发更高
配置简单,扩展性强
高可靠性
热部署
成本低、BSD许可证
安装
下载地址:http://nginx.org/en/download.html
解压后目录如下:
启动
双击nginx.exe,会有黑窗闪过。
用cmd命令窗口,cd 到nginx解压目录,
./nginx启动。在浏览器中访问
http://localhost:80,出现以下界面说明启动成功(由于笔者电脑80端口被占用,所以更改为8080,nginx默认为80端口)。
部署Vue项目
将build后的文件夹放到nginx目录下的html文件夹当中。
修改nginx.conf配置文件。
配置访问地址。
其他常用配置
跨域配置
代码:
location /api {
proxy_set_header Host ;
proxy_set_header X-Real-IP ;
proxy_set_header X-Forwarded-For ;
proxy_pass http://192.168.8.216:10000/api;
proxy_redirect default;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
}文件上传大小配置
代码:
client_max_body_size 50m; client_header_timeout 1m; client_body_timeout 1m; proxy_connect_timeout 60s; proxy_read_timeout 1m; proxy_send_timeout 1m;
Nginx部署Vue项目刷新404问题
代码:
location / {
root html/dist;
index index.html index.htm;
try_files / /index.html =;
autoindex on;
}常用命令
| 序号 | 命令 | 功能 |
|---|---|---|
| 1 | taskkill /im nginx.exe /f | 关闭所有nginx进程 |
| 2 | tasklist | find /i “nginx.exe” || exit | 查看nginx的进程使用情况 |
| 3 | taskkill /pid 1234 /f | 关闭指定进程 |
| 4 | ./nginx | 启动 |
| 5 | ./nginx-s stop | 停止 |
| 6 | ./nginx-s quit | 安全退出 |
| 7 | ./nginx-s reload | 重新加载配置文件 |
完整配置
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 400m;
client_header_timeout 5m;
client_body_timeout 5m;
proxy_connect_timeout 6000s;
proxy_read_timeout 5m;
proxy_send_timeout 5m;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name .168.8.216;
location / {
root html/dist;
index index.html index.htm;
try_files / /index.html =;
autoindex on;
}
location /api {
proxy_set_header Host ;
proxy_set_header X-Real-IP ;
proxy_set_header X-Forwarded-For ;
proxy_pasNginx是什么?
Nginx是什么?Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器 ,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶...
点击下载文档文档为doc格式
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
上一篇
已经是第一篇











