history模式 nginx配置_Vue history模式Nginx配置

vue开发使用history模式的时候Nginx相关的配置有如下两种:

1.此种配置直接使用的根域名,没有其他的二级路径,因此root直接指向目标文件夹,即包含index.html的文件夹路径

server {

listen 80;

listen 443 ssl;

server_name manager-qa.xxx.com;

ssl_certificate /etc/nginx/ssl/2319844__xxx.com.pem;

ssl_certificate_key /etc/nginx/ssl/2319844__xxx.com.key;

root /usr/share/nginx/;

#从系统时间中正则匹配出年月日

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {

set $date $1$2$3;

}

# 日期记录日志

access_log /var/log/nginx/$date-manager-qa.xxx.com.access.log;

location / {

root /usr/share/nginx/manager/qa/dist/;

try_files $uri $uri/ /index.html;

index index.html;

add_header Access-Control-Allow-Origin *;

}

}

2.此种配置适合同一域名下的多个项目,用二级路径来区别,不过root不再指向项目文件夹而是它的上一级

server {

listen 80;

listen 443 ssl;

server_name m-qa.xxx.com;

ssl_certificate /etc/nginx/ssl/2319844__xxx.com.pem;

ssl_certificate_key /etc/nginx/ssl/2319844__xxx.com.key;

root /usr/share/nginx/;

#从系统时间中正则匹配出年月日

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {

set $date $1$2$3;

}

# 日期记录日志

access_log /var/log/nginx/$date-manager-qa.xxx.com.access.log;

location /course {

try_files $uri $uri/ /course/index.html;

root /usr/share/nginx/qa/;

index index.html;

}

location /v2 {

try_files $uri $uri/ /v2/index.html;

root /usr/share/nginx/qa/;

index index.html;

}

}

你可能感兴趣的:(history模式,nginx配置)