在安装Nginx之后
/etc/nginx/nginx.conf 里面有一段
include /etc/nginx/conf.d/*.conf; 通常我们配置二级域名放在这里面
先来看一级域名配置
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;
include /etc/nginx/conf.d/*.conf; #通常我们配置二级域名放在这里面
server { server_name www.XXX.com; root /opt/dist; //VUE打包后的目录 #access_log logs/host.access.log main; location / { index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
# 如下SSL配置
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/api.yunpiaobox.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/api.yunpiaobox.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.yunpiaobox.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name www.yunpiaobox.com;
return 404; # managed by Certbot
}
}
到此结束
再来看二级域名. 如下是静态文件(HTTPS)访问配置
server { server_name img.XXX.com; location / { alias /img/; #autoindex on; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/api.yunpiaobox.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/api.yunpiaobox.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { if ($host = img.yunpiaobox.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name img.XXX.com; return 404; # managed by Certbot }
二级域名. 如下是端口映射访问配置 请求could.XXX.com 将会请求8080端口的服务
server { listen 80; server_name cloud.XXX.com; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://0.0.0.0:8080; }
access_log /var/log/nginx/cloud.XXX.com.log;
}