-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathnginx-ssl-reverse-proxy
198 lines (105 loc) · 4.46 KB
/
nginx-ssl-reverse-proxy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
#1
mkdir -p ~/ssl/certs
#2
mkdir -p ~/nginx/conf.d
#3
cd ~/nginx/conf.d
#4
apt update -y 2> /dev/null
apt install -y vim 2> /dev/null
yum update -y 2> /dev/null
yum install -y vim 2> /dev/null
#5
echo '
server {
listen 80;
server_name jira.cloudgeeks-ca.com;
return 301 https://$host$request_uri;
}
server {
server_name jira.cloudgeeks-ca.com;
listen 443 ssl;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/certs/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers TLS-CHACHA20-POLY1305-SHA256:TLS-AES-256-GCM-SHA384:TLS-AES-128-GCM-SHA256:HIGH:!aNULL:!MD5;
location / {
proxy_set_header Host $host:$server_port;
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;
proxy_redirect http:// https://;
proxy_pass http://10.192.5.126:8080;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
}
}' > ~/nginx/conf.d/server.conf
#6
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /root/ssl/certs/server.key -out /root/ssl/certs/server.crt
#7
docker run --name nginx --restart unless-stopped -v ~/ssl/certs:/etc/ssl/certs -v ~/nginx/conf.d:/etc/nginx/conf.d -p 443:443 -p 80:80 -d nginx
#END
#############################################################################################################################
# Docker Custom Bridge Network is recommended in order to communicate containers with container name.
docker network ls
docker network create --driver=bridge cloudgeeks-ca
#1 mkdir -p ~/nginx/ssl/certs
#2 mkdir -p ~/nginx/conf.d
#3 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ~/nginx/ssl/certs/nginx-selfsigned.key -out ~/nginx/ssl/certs/nginx-selfsigned.crt
#4 openssl dhparam -out /root/ssl/certs/dhparam.pem 2048
#5 cd ~/nginx/conf.d
#6 apt update -y && apt install -y vim
#7 vim ssl.conf
server {
listen 80;
server_name jira.cloudgeeks-ca.com;
return 301 https://$host$request_uri;
}
server {
server_name jira.cloudgeeks-ca.com;
listen 443 ssl;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/certs/nginx-selfsigned.key;
location / {
proxy_set_header Host $host:$server_port;
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;
proxy_redirect http:// https://;
proxy_pass http://jira:port;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;
}
}
#Note Proxy pass will be the container IP
#Example: docker inspect --format '{{ .NetworkSettings.IPAddress }}' fdeabb276a76
#8 docker run --name nginx --network=cloudgeeks-ca -v ~/nginx/ssl/certs:/etc/ssl/certs -v ~/nginx/ssl/certs:/etc/ssl/certs -v ~/nginx/conf.d:/etc/nginx/conf.d -p 443:443 -p 80:80 --restart unless-stopped -d nginx
#Note: You can also make an entry in /etc/hosts
#10.11.5.8 jira.saqlainmushtaq.com
# ping jira.saqlainmushtaq.com
###Configuration Location###
#Note: for Amazon Linux or Centos
#vim /etc/nginx/conf.d/server1.conf
#Note:for Ubuntu
#vim /etc/sites-available/server1.conf
#ln -s /etc/sites-available/server1.conf /etc/nginx/sites-enabled/server1.conf
###End###
Network settings
--dns=[] : Set custom dns servers for the container
--network="bridge" : Connect a container to a network
'bridge': create a network stack on the default Docker bridge
'none': no networking
'container:<name|id>': reuse another container's network stack
'host': use the Docker host network stack
'<network-name>|<network-id>': connect to a user-defined network
--network-alias=[] : Add network-scoped alias for the container
--add-host="" : Add a line to /etc/hosts (host:IP)
--mac-address="" : Sets the container's Ethernet device's MAC address
--ip="" : Sets the container's Ethernet device's IPv4 address
--ip6="" : Sets the container's Ethernet device's IPv6 address
--link-local-ip=[] : Sets one or more container's Ethernet device's link local IPv4/IPv6 addresses
https://docs.docker.com/engine/reference/run/