0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nginx と Spring Boot の連携

Posted at

Spring boot が ssl 利用してない場合、nginxの設定ファイルを以下のようにすればよいです。

nginx.conf
http {
    upstream server_com {
 	   server 127.0.0.1:8081;
    }
   
    server {
        listen       80;
	listen       [::]:80;
        server_name  localhost;

	location / {
	    proxy_http_version 1.1;
            proxy_pass      http://server_com;
            proxy_set_header        X-Forwarded-For   $remote_addr;
            proxy_set_header        X-Real-IP         $remote_addr;
            proxy_set_header        Host              $host;
            proxy_set_header Access-Control-Allow-Origin *;
            proxy_read_timeout 900;
	}	
    }

}

spring boot が ssl を利用する場合、

nginx.conf
http {
    
   
    server {
        listen       80;
	listen       [::]:80;
        server_name  localhost;
	#return       301 https://$host:4433$request_uri;
    }

	upstream server_com {
 	   server 127.0.0.1:8443;
    }


    # HTTPS server
    server {
        listen       4433 ssl;
	listen      [::]:4433 ssl;
        server_name  localhost;

        ssl_certificate      /path/to/cert.pem;
        ssl_certificate_key  path/to/cert.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            proxy_pass      https://server_com;
            proxy_set_header        X-Forwarded-For   $remote_addr;
            proxy_set_header        X-Real-IP         $remote_addr;
            proxy_set_header        Host              $host;
            proxy_set_header Access-Control-Allow-Origin *;
            proxy_read_timeout 900;
	}
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?