前端部署: nginx配置

前提:nginx 已安装html

简介:nginx(engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。国内分支Tengine。前端

部署:进入安装的 nginx 目录,找到 nginx.conf 文件(查找命令:)nginx

查找命令:find / -name nginx.conf
或者 whereis nginx.config

找对本身要编辑的 nginx.config 文件web

进入对应目录,编辑文件:vim nginx.conf :数据库

   下面是个人配置:vim

   说明:因为默认 端口80 被占用,需从新配置一个 server 服务,此处设置了不一样的端口。设置以下:服务器

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

# 新添加部分:因为默认端口被占用,需从新配置一个 server 服务,此处设置了不一样的端口。 server {   listen 6789; # 前端显示的 port   server_name localhost; # 服务器地址   root /usr/local/network_xx/web; # 文件存放的地址,也就是 前端代码(通常是index.html+其余前端全部的文件放置的) 放置的目录地址   index index.html; # 入口文件   charset utf-8; # 编码   access_log /var/log/nginx/access.log; # 使用日志,地址与默认地址保持一致   error_log /var/log/nginx/error.log; # 错误日志,地址与默认地址保持一致 } }

 

参考以下:antd

// 参考:
server {
        listen       80;
        server_name  localhost;
        location / {
            proxy_pass http://www.baidu.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

 

配置完成后,须要从新加载启动。app

1. nginx -s stop
2. nginx -c ../../../nginx.conf  // 本身的 nginx.conf 路径
3. nginx -s reload
//nginx 等价于 /nginx安装路径/sbin/nginx

注:上述 nginx -* ... 不起做用是由于没有配置默认路径

 可直接进入nginx路径,/nginx安装路径/sbin/,再使用命令 ./nginx -s reload tcp

 


systemctl stop nginx
systemctl start nginx nginx 启动: 直接 nginx 便可 更多命令:nginx 使用手册,查看手册命令: man nginx

 

 antd pro 前端部署:- Nginx配置

user root;
worker_processes  1;
error_log /usr/local/nginx/log/error.log;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
            autoindex on;
        }

        // 后台路由配置
        location ^~/ippool/ {
            proxy_pass http://**.**.**.**:2000/;
        }
        location ^~/susu/ {
            proxy_pass http://**.**.**.**:2000/;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 

出现 Request Entity Too Large问题的解决方法

两种状况:

  • 带413:413 Request Entity Too Large,是请求文件太大(不包含参数)
  • 不带413:Request Entity Too Large,是请求实体太大(包含参数,文件等)

客户端发送的实体主体部分比服务器可以或者但愿处理的要大。 
出现这个状态码的通常都是上传接口。

通常解决办法:

1. 查看反代设置

nginx 中: client_max_body_size 具体的大小值,默认为1m; 此时可调整大小

2. 查看应用的设置

通常多是 web 项目中配置的大小不够。查看应用设置(好比,数据库字段长度设置)

3. 服务器运行状况是否正常

 

参考:https://mp.weixin.qq.com/s?__biz=MzU5MjUwNzk1NQ==&mid=2247484128&idx=1&sn=bf63f0709fc2c86909eb23d7379b74bb&chksm=fe1fe7bcc9686eaac5a9b7155cccb7206ea826e3a967f146d01061e7400a477d814bab734be9&mpshare=1&scene=1&srcid=0228k3B4tUZrpPsnFUNehPcd#rd

相关文章
相关标签/搜索