nginx配置中英文版多个VUE项目

Godaddy SSL配置文件下载下来有两个.crt
合并一下放到服务器里

cat 700fdd5d829fd2a3.crt gd_bundle-g2-g1.crt >> tyt.crt

/etc/nginx/nginx.conf

user root; # 配置用户组
worker_processes 2; # 允许生成最大进程数
pid /run/nginx.pid; # nginx运行文件存放地址

events {
    use epoll; # 驱动模型
    worker_connections 1024; # 单进程最大并发数
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##
    # sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
    # 对于普通应用,必须设为 on,
    # 如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
    # 以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # 该指令用于设置Nginx服务器允许的客户端请求头部的缓冲区大小,默认为1KB,此指令的赋值可以根据系统分页大小来设置,分页大小可以用以下命令获取getconf PAGESIZE。
    client_header_buffer_size 4k;
    # 客户端上传的body的最大值。超过最大值就会发生413(Request Entity Too Large)错误。默认为1m,最好根据自己的情况改大一点。
    client_max_body_size 8m;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;  # 请求消息类型
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    # access_log /var/log/nginx/access.log;
    # error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##
    # 压缩
    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    #  include /etc/nginx/conf.d/*.conf;
    #  include /etc/nginx/sites-enabled/*;
    # 负载均衡池
    # apis
    upstream api_pool{
            server 127.0.0.1:8080;
    }
    
    # https
    server {
            listen 443 ssl;
            server_name tyt.io;
            ssl on;
            ssl_certificate /etc/nginx/key/tyt.crt;
            ssl_certificate_key /etc/nginx/key/tyt.key;
            ssl_session_timeout 5m;
                # 指定SSL服务器端支持的协议版本
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
                # 在使用SSLv3和TLS协议时指定服务器的加密算法要优先于客户端的加密算法
            ssl_prefer_server_ciphers on;  
            access_log /var/log/nginx/access_ssl.log;
            error_log /var/log/nginx/error_ssl.log;
            # 静态文件目录
            root /awww;
            location / {
                    # 默认跳转到/en-US
                    rewrite ^/(.*) https://$server_name/en-US$request_uri;
            }
            location /en-US {
                    # 部署多个VUE项目
                    try_files $uri $uri/ /en-US/index.html;
            }
            location /zh-CN {
                    # 部署多个VUE项目
                    try_files $uri $uri/ /zh-CN/index.html;
            }
            location ~ ^/(images|javascript|js|css|flash|media|static)/ {
                    # 过期30天,静态文件不怎么更新,过期可以设大一点,
                    # 如果频繁更新,则可以设置得小一点。
                    expires 30d;
            }
    }
    # http
    server {  
            listen 80;         
            server_name tyt.io;  
            # 跳转到HTTPS
            rewrite ^/(.*) https://$server_name$request_uri;  
    } 
    # api.tyt.io 映射到8080端口上
    server {
            listen 80;
            server_name api.tyt.io;
            access_log /var/log/nginx/access_api.log;
            error_log /var/log/nginx/error_api.log;
            location / {
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://api_pool;
            }
    }
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

其中子域名需要在DNS解析设置中添加记录

api.tyt.io

部署多个vue项目时
例如英文版部署到服务器/awww/en-US/中
index.html里添加

  ...
  <meta base="/en-US/">
  ...
  <!-- /en-US/加上这个 -->
  <link rel="shortcut icon" href="/en-US/static/20x20.png" type="image/x-icon">
  ...

build配置修改 config/index.js

build: {
  ...
  assetsPublicPath: '/en-US/',
  ...
}

路由配置修改 router/index.js

export default new Router({
  base: '/en-US/',
  mode: 'history',
  ...
}

推荐阅读更多精彩内容