Nginx 安装及对 antd Pro 项目进行 nginx 配置和 gzip 压缩

2,226 阅读1分钟

安装


更新update

apt-get update

安装 nginx

sudo apt-get install nginx

查看是否安装成功

nginx -v

运行 nginx


启动 nginx

service nginx start

查看 nginx 是否启动

ps -ef | grep nginx

停止 nginx

service nginx stop

重启 nginx

service nginx restart

配置 nginx 服务


修改配置文件 nginx.conf

vim /etc/nginx/nginx.conf

antd Pro 配置信息

    server {
        listen 80;
        # gzip config
        gzip on;
        gzip_min_length 1k;
        gzip_comp_level 9;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";

        root ~/weData/build/index.html;

        location / {
            # 用于配合 browserHistory使用
            try_files $uri $uri/ /index.html;

            # 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验
            # rewrite ^/(.*)$ https://preview.pro.ant.design/$1 permanent;

        }
        location /api {
            proxy_pass https://localhost:8080/;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   X-Real-IP         $remote_addr;
        }
    }