1、静态资源(html)

server {
        listen       80;
        root /usr/share/nginx/html;
        index index.html;
       
        location / {
             root /usr/share/nginx/html;
		     try_files $uri $uri/ /index.html;
        }
}

说明1: 未配置域名,仅通过ip访问

说明2: root 指明静态资源路径

说明3: try_files 解决刷新404

2、多个URI,不同路径

server {
        listen       8080;
        server_name  localhost;
        index index.html;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /h5 {
            root   /opt/apache-tomcat-8.5.64/webapps;
            index  index.html;
            #try_files $uri $uri/ /index.html;
        }

        location / {
            root   /home/webapps/jeeplus/dist;
            index  index.html;
            #try_files $uri $uri/ /index.html;
        }
}

说明1: 不同静态文件,不同URI映射不同路径

说明2: 访问连接

http://127.0.0.1:8080/h5/index.html

对应的路径为:

真实路径携带URI的h5,需留意,不然访问会404

~~

3、vue打包后

1)配置

server {
     listen 80;
    server_name localhost 192.168.0.1;
    # gzip config
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";

    location / {
        root /var/lib/jenkins/workspace/hg-demo/dist;
        index index.html;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_send_timeout      30m;
        proxy_read_timeout      30m;
        client_max_body_size    100m;
        try_files $uri $uri/ /index.html;
    }
   }

~~

4、nginx报错zero size shared memory zone one

1)注释掉: limit_conn

2)原因: 没有nginx未支持此模块【http_limit_conn_zone】

~~

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐