Nginx配置

# 前端
server {
    listen 18000;
    server_name 192.168.254.150;

    location / {
	    autoindex on;
        root /home/jiuzhi/online-student-frontend-pc/dist;
        index index.html index.htm;
        try_files $uri $uri/ /index.html; 
    }
}


# 后端
server {
    listen 18009;
    server_name 192.168.254.150;

    location / {
        include  uwsgi_params;
        proxy_pass http://127.0.0.1:8009;
    }


        # 告诉浏览器允许跨域访问的方法
        add_header Access-Control-Allow-Methods *;

        # 告诉浏览器缓存OPTIONS预检请求1小时
        add_header Access-Control-Max-Age 3600;

        # 允许带有cookie访问
        add_header Access-Control-Allow-Credentials true;

        # 注意*不能满足带有cookie的访问,origin必须是全匹配
        # 服务器与nginx只能存在一个跨域配置
        add_header Access-Control-Allow-Origin * always;

        # 设置支持所有的自定义请求头
        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        # 如果预检请求,则返回成功,不需要转发给后端
        if ($request_method = OPTIONS){
                return 204;
        }
}


# 静态文件夹
server {
    listen 18011;
    server_name 192.168.254.150;


    location /file {
        alias /home/static/file;
	autoindex on;

    }

    location /diploma {
        alias /home/static/diploma;
	autoindex on;

    }

	    # 告诉浏览器允许跨域访问的方法
        add_header Access-Control-Allow-Methods *;

        # 告诉浏览器缓存OPTIONS预检请求1小时
        add_header Access-Control-Max-Age 3600;

        # 允许带有cookie访问
        add_header Access-Control-Allow-Credentials true;

        # 注意*不能满足带有cookie的访问,origin必须是全匹配
        # 服务器与nginx只能存在一个跨域配置
        add_header Access-Control-Allow-Origin * always;

        # 设置支持所有的自定义请求头
        add_header Access-Control-Allow-Headers $http_access_control_request_headers;

        # 如果预检请求,则返回成功,不需要转发给后端
        if ($request_method = OPTIONS){
                return 204;
        }
}

前端路径直到项目下的dist,只配置到项目,会出现304

你可能感兴趣的:(nginx,nginx)