1 回答
TA贡献1817条经验 获得超6个赞
NGinx 在路径上应用优先级,意味着如果从顶部开始的路径匹配,则不会检查后续路径。location /应该一直在最后。
容器应该共享一个网络以便能够互相看到,而不必暴露或与主机共享端口。
NGinx 配置:
server {
listen 80;
listen [::]:80;
server_name braurl.se www.braurl.se;
#for certbot challenges (renewal process)
location ~ /.well-known/acme-challenge {
allow all;
root /data/letsencrypt;
}
location / { # Always at this end (everything else)
# This redirs to either www.braurl.se or braurl.se but with https.
rewrite ^ https://$host$request_uri? permanent;
}
}
-----------------------
#https://braurl.se
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name braurl.se www.braurl.se;
server_tokens off;
ssl_certificate /etc/letsencrypt/live/braurl.se/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/braurl.se/privkey.pem;
ssl_buffer_size 8k;
ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;
ssl_ecdh_curve secp384r1;
ssl_session_tickets off;
# OCSP stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8;
root /usr/share/nginx/html;
index index.html;
location /api/ { # this First, NGinx use priority, if path match, it won't check the next path
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://goservice:8080;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
# Always try index files, this is for React.
location / { # Always at this end (everything else)
try_files $uri /index.html;
}
}
码头工人-compose.yml
version: '3.1'
services:
goservice:
build: "."
image: golang
container_name: goservice
expose:
- "8080" # <-- change port number, Dockerfile EXPOSE 8080
networks: # <-- Add this
- random_name # <-- Add this
# ports: # <-- To Remove
# - "8080:8080" # <-- To Remove
production-nginx-container:
container_name: 'production-nginx-container'
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./production.conf:/etc/nginx/conf.d/default.conf
- ./production-site:/usr/share/nginx/html
- ./dh-param/dhparam-2048.pem:/etc/ssl/certs/dhparam-2048.pem
- /docker-volumes/etc/letsencrypt/live/braurl.se/fullchain.pem:/etc/letsencrypt/live/braurl.se/fullchain.pem
- /docker-volumes/etc/letsencrypt/live/braurl.se/privkey.pem:/etc/letsencrypt/live/braurl.se/privkey.pem
depends_on:
- "goservice"
networks: # <-- Add this
- random_name # <-- Add this
networks:
- random_name:
现在您可以使用访问前端https://braurl.se和使用 APIhttps://braurl.se/api/
- 1 回答
- 0 关注
- 162 浏览
添加回答
举报
