前提:nginx 已安装

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

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

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

找对自己要编辑的 nginx.config 文件

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

   下面是我的配置:

   说明:由于默认 端口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; # 错误日志,地址与默认地址保持一致 } }

 

参考如下:

// 参考:
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;
        }
}

 

配置完成后,需要重新加载启动。

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 

 


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

posted on 2019-03-26 09:36  云雀sunshine  阅读(19788)  评论(0编辑  收藏  举报