标签:buffers test bash 虚拟 list XML sch highlight 作用
飘过。。。
cd /etc/nginx
sudo vi nginx.conf
sudo find /etc -name nginx.conf //在 /etc 目录下查找 nginx.conf 配置文件
sudo locate nginx.conf //locate 是在后台数据库中按文件名搜索 , 搜索速度比 find 更快 , 但对于刚建立的文件 , 使用该命令进行查找将会搜索不到所创建的文件 , 如果想使刚创建的文件被 locate 命令搜索到 , 可以使用 updatedb 命令 , 更新 mlocate 数据库
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto; #启动进程
error_log /var/log/nginx/error.log; #全局错误日志
pid /run/nginx.pid; #PID文件
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024; #单个后台worker process进程的最大并发链接数
}
http {
gzip on; #开启gzip压缩
gzip_min_length 1k; #设置对数据启用压缩的最少字节数
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 6; #设置数据的压缩等级,等级为1-9,压缩比从小到大
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; #设置需要压缩的数据格式
gzip_vary on;
#虚拟主机配置
server {
listen 80;< 大专栏 Nginx部署前后端分离服务/span>
server_name mark.binlive.cn;
root /home/spa-project/dist; #定义服务器的默认网站根目录位置
index index.html; #定义index页面
error_page 404 /index.html; #将404错误页面重定向到index.html可以解决history模式访问不到页面问题
location ^~ /api/{
proxy_pass http://127.0.0.1:7000;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
client_max_body_size 2048m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ^~ /auth/{
proxy_pass http://127.0.0.1:7000;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
client_max_body_size 2048m;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
将前端代码打包后的dist文件放入指定服务目录
将服务目录指定到spa-project/dist目录下即可代理静态服务
配置里开启了gzip压缩,可以很大程度上减小文件体积大小
将404错误页面重定向到index.html,可以解决前端history路由模式由于刷新页面访问不到服务出现404的问题
location为代理接口,可以转发代理后端的请求接口域名或者ip,即可解决接口跨域问题
nginx -t //测试Nginx的配置是否正确
nginx //在配置文件正确的情况下即可启动nginx服务
nginx -s reload
nginx: [emerg] getpwnam("nginx") failed in /etc/nginx/nginx.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
END
Thanks!
https://segmentfault.com/a/1190000014972747
https://serverfault.com/questions/581145/getpwnamwww-failed-in-etc-nginx-nginx-conf
https://blog.csdn.net/tojohnonly/article/details/70160388
标签:buffers test bash 虚拟 list XML sch highlight 作用
原文地址:https://www.cnblogs.com/lijianming180/p/12041274.html