1.博主本测次配置针对windows,linux其实一样的道理
2.tomcat 8.55.0 nginx 1.25.1
3.步骤:
3.1nginx.conf内容:
worker_processes 1;events {worker_connections 2048;
}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 650;
gzip on;
# 不压缩临界值,大于1K的才压缩,一般不用改
gzip_min_length 1k;
# 压缩缓冲区
gzip_buffers 16 64K;
# 压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
gzip_http_version 1.1;
# 压缩级别,1-10,数字越大压缩的越好,时间也越长
gzip_comp_level 5;
# 进行压缩的文件类型
gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
# 跟Squid等缓存服务有关,on的话会在Header里增加"Vary: Accept-Encoding"
gzip_vary on;
# IE6对Gzip不怎么友好,不给它Gzip了
gzip_disable "MSIE [1-6]\.";
server_names_hash_bucket_size 128;client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 300m;tcp_nopush on;tcp_nodelay on;client_body_buffer_size 512k;proxy_connect_timeout 180;proxy_read_timeout 3000;proxy_send_timeout 3000;proxy_buffer_size 256k;proxy_buffers 4 256k;proxy_busy_buffers_size 256k;proxy_temp_file_write_size 256k;proxy_hide_header X-Powered-By;server_name_in_redirect off;map_hash_bucket_size 1024;map_hash_max_size 102400;charset utf-8;server {listen 443 ssl;server_name ****.****.com;ssl_certificate D://******.com.pem;ssl_certificate_key D://******.com.key;ssl_protocols TLSv1.2 TLSv1.3;ssl_prefer_server_ciphers on;ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM';location / {proxy_pass http://localhost:7601;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;}}}
3.2 博主tomcat内容比较简单,不进行粘贴了:tomcate项目启动端口是7061,先启动tomcat在启动nginx即可。
3.3后续发现部分博主反映虽然主页正常单部分报错 ,会出现CORS错误,解决办法为:
3.3.1修改tomcat配置server.xml文件:
connector里添加
-
redirectPort="443"
-
roxyPrort="443
-
<Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="443"proxyPrort="443"maxParameterCount="1000"/>
3.3.2host里添加:
<Valve className="org.apache.catalina.valves.RemoteIpValve" protocolHeaderHttpsValue="https" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" />
3.3.3host代码块添加完后如下: 注意实在host节点里添加了value的子节点
最终成功展现:
达成效果:能够将非主流端口全部通过nginx转到80 或者443,很好用。