部署完前端服务,样式没有了 Sorry, we need js to run correctly!

Saber 未结 1 50
bigBug
bigBug 剑童 2025-04-02 16:53

rver_name reazh.com; #需要将yourdomain替换成证书绑定的域名。

    #

    # rewrite ^(.*)$ https://www.reazh.com/$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。

    #

    # location / {

    #    index index.html index.htm;

    # }

    #}


    server {

        #listen       443 ssl;

listen       80;

        listen       [::]:80;

        server_name  www.ceshi.com;

#server_name 192.168.1.7;

#server_name 127.0.0.1;

        root         D:/nginx-1.22.1/html;

#add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Origin *;

add_header Access-Control-Allow-Credentials true;

add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

#ssl_certificate cert/cert.pem;  

    #ssl_certificate_key cert/cert.key; 

    #ssl_session_timeout 5m;

    #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

    #ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; 

#ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.

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


        error_page 404 /404.html;

        location = /404.html {

        }


        error_page 500 502 503 504 /50x.html;

        location = /50x.html {

        }

location / {

alias html/dist;

index index.html index.htm;

}

location /web {

alias html/dist;

#root /usr/share/nginx/html/;

index index.html index.htm;

try_files $uri $uri/ /index.html;

}


#location @router {

#   rewrite ^.*$ /index.html last;

#}

location @router {

rewrite (static/.*)$ /$1 redirect;

rewrite ^.*$ /index.html last;

}


location ^~/api-resource { # 电子资源

   # 后端的真实接口

   proxy_pass http://127.0.0.1:8082/;#网关地址

   proxy_redirect off;

   proxy_set_header Host $host;

   proxy_set_header X-Real-IP $remote_addr;

   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

   proxy_set_header   Cookie $http_cookie;

   # for Ajax

   #fastcgi_param HTTP_X_REQUESTED_WITH $http_x_requested_with;

   proxy_set_header HTTP-X-REQUESTED-WITH $http_x_requested_with;

   proxy_set_header HTTP_X_REQUESTED_WITH $http_x_requested_with;

   proxy_set_header x-requested-with $http_x_requested_with;

   client_max_body_size 100m;

   client_body_buffer_size 128k;

   proxy_connect_timeout 90;

   proxy_send_timeout 90;

   proxy_read_timeout 90;

   proxy_buffer_size 128k;

   proxy_buffers 32 32k;

   proxy_busy_buffers_size 128k;

   proxy_temp_file_write_size 128k;

}

#location /web {

# 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_set_header X-Forwarded-Proto  $scheme;

# proxy_pass      http://127.0.0.1:1888/;

# }


#location /shuzitushu-book {

# alias html/shuzitushu-book;

        #        index index.html index.htm;

#}


#location / {

# alias html/dist/;

# index index.html index.htm;

#}


location ^~/api/ {

proxy_read_timeout 600s;

                        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_set_header X-Forwarded-Proto  $scheme;

                        proxy_pass      http://127.0.0.1:8080/;

        }



image.png

1条回答
  • 2025-04-03 09:53

    把打包后的内容放到 nginx的 html文件夹根目录,不要带dist,也不要做alias

    0 讨论(0)
代码语言
提交回复