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 {
    #        }
    #    }
    
    }
  • 相关阅读:
    Spring中的@Valid 和 @Validated注解你用对了吗
    linux 安装php_fileinfo扩展
    长链接,案例
    小程序,if 语句嵌入控制class 内容
    脚本执行,log 换行符号 PHP_EOL
    查看ip,某端口是否开启
    Out-of-core classification of text documents of sklearn
    Working With Text Data of sklearn
    docstring of python
    Manifold learning of sklearn
  • 原文地址:https://www.cnblogs.com/eason-d/p/8365078.html
Copyright © 2011-2022 走看看