Nginx(http配置、https配置)访问Spring Boot 项目
    		       		warning:
    		            这篇文章距离上次修改已过424天,其中的内容可能已经有所变动。
    		        
        		                
                要使用Nginx作为反向代理服务器来访问Spring Boot项目,你需要配置Nginx的HTTP和HTTPS设置。以下是基本的配置示例:
- 对于HTTP配置,你需要将所有的HTTP请求重定向到HTTPS:
server {
    listen 80;
    server_name your-domain.com;
 
    # 重定向所有HTTP请求到HTTPS
    return 301 https://$server_name$request_uri;
}- 对于HTTPS配置,你需要正确配置SSL证书,并将请求代理到Spring Boot应用程序的端口:
server {
    listen 443 ssl;
    server_name your-domain.com;
 
    # SSL证书和私钥的路径
    ssl_certificate /path/to/your/fullchain.pem;
    ssl_certificate_key /path/to/your/private.key;
 
    # 配置Spring Boot应用程序的代理设置
    location / {
        proxy_pass http://localhost:8080; # Spring Boot应用程序的端口
        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;
    }
}确保替换your-domain.com, /path/to/your/fullchain.pem, /path/to/your/private.key, 和localhost:8080为你的实际域名、SSL证书路径和Spring Boot应用程序的端口号。
这样配置后,Nginx会监听443端口的HTTPS请求,并将其代理到运行在8080端口的Spring Boot应用程序。同时,它会自动将所有HTTP请求重定向到HTTPS。
评论已关闭