nginx配置上遇到的问题

1. 把cheap-quasar改造成ssr后,nginx的配置也需要改

原来的

server {
    listen 443 ssl;  # 1.1版本后这样写
    server_name hjdang.com www.hjdang.com; #填写绑定证书的域名i
    #一级域名统一转到www的二级域名
     if ($http_host ~ "^hjdang.com$") {
        rewrite  ^(.*)    https://www.hjdang.com$1 permanent;
    }
    root /home/hjdang/hjdang-web;
    access_log  /data/log/nginx/www.hjdang.log  main;
    ssl_certificate /etc/nginx/ssl/hjdang.com_bundle.crt;  # 指定证书的位置,绝对路径
    ssl_certificate_key /etc/nginx/ssl/hjdang.com.key;  # 绝对路径,同上
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
    ssl_prefer_server_ciphers on;
    location / {
        try_files $uri $uri/ /index.html;
        index index.html;
        add_header Cache-Control "no-store,max-age=0";

#       if ($request_filename ~* .*\.(?:htm|html)$)
#       {
#               add_header Cache-Control "no-store";
                #对html文件设置永远不缓存
#       }
    }

   # location @router {
   #     rewrite ^.*$ /index.html last;
   # }

    location ~* \.(html)$ {
          access_log off;
          add_header  Cache-Control  "no-store,max-age=0";
    }
    location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
         access_log off;
         add_header Cache-Control max-age=604800;
    }


}

改成了

server {
    listen 443 ssl;  # 1.1版本后这样写
    server_name hjdang.com www.hjdang.com; #填写绑定证书的域名i
    #一级域名统一转到www的二级域名
     if ($http_host ~ "^hjdang.com$") {
        rewrite  ^(.*)    https://www.hjdang.com$1 permanent;
    }
    root /home/hjdang/hjdang-web;
    access_log  /data/log/nginx/www.hjdang.log  main;
    ssl_certificate /etc/nginx/ssl/hjdang.com_bundle.crt;  # 指定证书的位置,绝对路径
    ssl_certificate_key /etc/nginx/ssl/hjdang.com.key;  # 绝对路径,同上
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
    ssl_prefer_server_ciphers on;
    location / {
        proxy_pass   http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        send_timeout 600;
        proxy_connect_timeout 300;
        proxy_send_timeout 300;
        proxy_read_timeout 300;
        proxy_buffer_size 128k;
        proxy_buffers 2 256k;
        proxy_busy_buffers_size 256k;
        proxy_temp_file_write_size 256k;
        client_max_body_size 10m;
        add_header Cache-Control "no-store,max-age=0";

    }

   # location @router {
   #     rewrite ^.*$ /index.html last;
   # }

    location ~* \.(html)$ {
          access_log off;
          add_header  Cache-Control  "no-store,max-age=0";
    }
    location ~* \.(css|js|png|jpg|jpeg|gif|gz|svg|mp4|ogg|ogv|webm|htc|xml|woff)$ {
         access_log off;
         add_header Cache-Control max-age=604800;
    }


}

这时如果不把加粗部分删除,那些css会报404,页面就乱了。

posted @ 2023-03-30 03:27  zjhgx  阅读(109)  评论(0编辑  收藏  举报