nginx配置上遇到的问题

Posted zjhgx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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,页面就乱了。

以上是关于nginx配置上遇到的问题的主要内容,如果未能解决你的问题,请参考以下文章

使用tp3.2框架开发的项目在nginx上配置rewrite规则时遇到的问题

nginx服务器上遇到了acces denied,报错是fastCGI只要好好修改配置就行了

Nginx 配置问题 server directive is not allowed here in /etc/nginx/nginx.conf:69

在学django,在线上部署时候,采用nginx + fastcgi部署遇到问题

在 Beanstalk 上扩展 Nginx 配置不会正确重写 url

Nginx配置白名单策略遇到问题