nginx
配置如下:
upstream api_service {
server 127.0.0.1:8080 max_fails=3 fail_timeout=30;
ip_hash;
keepalive 256;
}
# 支持http访问
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
#root /root/h5/dist;
index index.html index.htm;
}
location /app/file/{
alias /app/file/;
}
location /app/image/{
alias /app/image/;
}
location ^~ /api/ {
proxy_pass http://api_service;
proxy_intercept_errors on;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 1024m;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
# 支持https 访问
server {
listen 443 ssl;
server_name localhost;
#ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/3256777_www.rxceping.com.pem;
ssl_certificate_key cert/3256777_www.rxceping.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ^~ /api/ {
proxy_pass http://api_service;
proxy_intercept_errors on;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 1024m;
}
}
配置完成之后,执行nginx -t
检查配置是否有问题
欢迎关注我的微信公众号,里面有很多干货,各种面试题