Nginx的安装、使用大家一定都会,也有很多教程,我记录一下配置
SSL使用的是阿里的免费SSL
server {
listen 443 ssl;
server_name XXXXXXX.com;
ssl_certificate XXXXXXX.pem;
ssl_certificate_key XXXXXXX.key;
client_header_timeout 120s;
client_body_timeout 120s;
client_max_body_size 100M;
# gzip config
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
location /wxh5 {
alias D:/Project/test/h5/;
index index.html;
try_files $uri $uri/ @router;
}
location / {
root D:/Project/test/web;
index index.html;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.html?s=$1 last;
break;
}
#try_files $uri $uri/ @router;
}
location /api{
proxy_pass http://localhost:8082/vote/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
一点点简单的说明:
alias和root的区别:在于对URI的处理方法不同。
alias是一个目录别名的定义,root则是最上层目录的定义
alias后面要用“/”结束,而root则可有可无