80 端口
server {
listen 80 default_server;
server_name _;
access_log off;
return 444;
}
443 端口同样需要限制,可以重定向到自己的域名。
server {
listen 443 ssl default_server;
server_name _;
ssl_certificate /etc/ssl证书;
ssl_certificate_key /etc/ssl证书;
rewrite ^(.*) https://allasone.cc;
}
add_header X-Frame-Options SAMEORIGIN;
# tomcat
upstream tomcatserver {
server 127.0.0.1:9090 weight=1;
server 127.0.0.1:9091 weight=1;
}
# 80端口
server {
listen 80;
server_name tomcat.allasone.cc;
rewrite ^(.*) https://tomcat.allasone.cc$1 permanent;
}
# 443端口
server {
listen 443 ssl;
server_name tomcat.allasone.cc;
ssl_certificate /etc/ssl证书;
ssl_certificate_key /etc/ssl证书;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://tomcatserver;
proxy_redirect default;
}
}
在一些类似验证网站所有权的场景下,需要配置二级目录映射静态文件。比如提交Google收录时,需要将Google提供的页面上传到网站。
server {
listen 443 ssl;
server_name www.allasone.cc allasone.cc;
include cert_certbot.conf;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
localtion / googlexxxxxxxxxxx.html {
alias /filepath/googlexxxxxxxxxxx.html;
}
location / {
proxy_pass http://xxx.xxx.xxx.xxx:xxxx/;
}
}
该静态页面的路径映射必须放在根路径映射“/”之前,否则不会生效。
……
# 请求体大小限制(通常用于文件上传)
client_max_body_size 10m;
# 屏蔽版本号(不显示nginx版本)
server_tokens off;
Q.E.D.