zoukankan      html  css  js  c++  java
  • Nginx 前后端分离配置 分发

    前端项目VUE  端口8081 , 后端项目JAVA 端口8080

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;
    
        server {
            listen       80;
            server_name  *.android-pos.cn;
            
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
        
          
          location  / {
              proxy_set_header   Host             $host;
              proxy_set_header   X-Real-IP        $remote_addr;
              #Web服务器可以通过X-Forwarded-For获取用户真实IP
              proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
               #以上三行,目的是将代理服务器收到的用户的信息传到真实服务器上
            
              if ($host ~ ^(http://)?api.android-pos.cn){
                  proxy_pass http://127.0.0.1:8080;
              }
              proxy_pass  http://127.0.0.1:8081;
          }
    
          #查看nginx运行的状态
          location /ngx_status{
              stub_status on;
              access_log off;
          }    
       
          #图片缓存时间      
            location ~ .*.(gif|jpg|jpeg|png|bmp|swf|svg)$ {
                root /opt/tomcat/webapps/ROOT/;
                expires 1h;
            }

          #js, css缓存
          location ~ .*.(js|css)$ {
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8080;
            proxy_redirect off;
            #proxy_cache cache_one;
            proxy_cache_valid 200 302 1h;
            proxy_cache_valid 301 1h;
            proxy_cache_valid any 1m;
            expires 4h;
          }

          #JS 和 CSS缓存时间    
          location ~ .*.(js|css)?$ {
                root /opt/tomcat/webapps/ROOT/;
            expires 1h;
            }
        
            error_page 404 /404.html;
                location = /40x.html {
            }
    
            error_page 500 503 504 /50x.html;
                location = /50x.html {
            }
        
          error_page 502 /502.html;
          location = /502.html {
               root html;
          }
        }
    
    # Settings for a TLS enabled server.
    #
    #    server {
    #        listen       443 ssl http2 default_server;
    #        listen       [::]:443 ssl http2 default_server;
    #        server_name  _;
    #        root         /usr/share/nginx/html;
    #
    #        ssl_certificate "/etc/pki/nginx/server.crt";
    #        ssl_certificate_key "/etc/pki/nginx/private/server.key";
    #        ssl_session_cache shared:SSL:1m;
    #        ssl_session_timeout  10m;
    #        ssl_ciphers HIGH:!aNULL:!MD5;
    #        ssl_prefer_server_ciphers on;
    #
    #        # Load configuration files for the default server block.
    #        include /etc/nginx/default.d/*.conf;
    #
    #        location / {
    #        }
    #
    #        error_page 404 /404.html;
    #            location = /40x.html {
    #        }
    #
    #        error_page 500 502 503 504 /50x.html;
    #            location = /50x.html {
    #        }
    #    }
    
    }
  • 相关阅读:
    css3 动画
    jQuery toast 淡入淡出提示
    JavaScript事件——拖拉事件
    Vue -- element-ui 限制只能输入number
    css 移动端页面,在ios中,margin-bottom 没有生效
    django 快速搭建blog
    python 正则表达式口诀
    [转]python os模块 常用命令
    【转】scapy 构造以太网注入帧
    【转】关于Scapy
  • 原文地址:https://www.cnblogs.com/eason-d/p/8365078.html
Copyright © 2011-2022 走看看