我有一個位置指令
location /nextcloud {
proxy_pass http://nextcloud_container:80/;
}
當我訪問http://192.168.40.231:408/nextcloud時,頁面加載正常,因為它傳遞到我的 nextcloud docker 地址http://192.168.1.2:80(只是一個示例容器地址)。
問題是它丟失了所有 css 檔案,因為對這些檔案的請求將轉到http://192.168.40.231:408/style.css而不是http://192.168.1.2:80/style.css(只是一個例子容器地址)。這同樣適用于重定向到其他頁面示例)/page2.html
所以我想要發生的是:
- 當我訪問/nextcloud時, nextcloud 容器所做的所有檔案和頁面重定向都應附加到/nextcloud的末尾,例如)nextcloud/style.css。這樣style.css檔案就不是宿主機地址而是傳遞給容器的。
- 還有其他位置指令我想做同樣的事情
nginx.conf
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
proxy_buffering off;
proxy_cache off;
proxy_http_version 1.1;
server {
listen 80;
server_name nginx_container;
location /nextcloud {
proxy_pass http://nextcloud_container:80/;
}
location /syncthing {
proxy_pass http://syncthing_container:8384/;
}
}
}
碼頭工人-compose.yml
version: "3"
services:
nginx:
image: nginx
build: ./nginx
container_name: nginx_container
ports:
- 408:80
networks:
- primary_network
nextcloud:
container_name: nextcloud_container
image: nextcloud
build: ./nextcloud
networks:
- primary_network
syncthing:
container_name: syncthing_container
image: syncthing/syncthing
build: ./syncthing
ports:
- 22000:22000/tcp # TCP file transfers
- 22000:22000/udp # QUIC file transfers
- 21027:21027/udp # Receive local discovery broadcasts
restart: unless-stopped
networks:
- primary_network
networks:
primary_network:
ipam:
driver: default
這是我發現的一個類似問題,如果這個問題更容易理解當 URL 子目錄發生變化時,如何使用 Nginx 作為 Nextcloud 的代理?
uj5u.com熱心網友回復:
我想出了一個解決方案,您只需將每個服務映射到具有唯一埠的新服務器塊。這里有一些代碼可以更好地說明我的意思。
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
proxy_buffering off;
proxy_cache off;
proxy_http_version 1.1;
# Redirects http traffic to https blocks below
server {
listen 80;
server_name xx.xx.xx.xx;
return 302 https://$server_name$request_uri;
}
# SSL Configurations
include /etc/nginx/nginx_ssl.conf;
# NextCloud
server {
listen 443 ssl;
server_name xx.xx.xx.xx;
# Reverse proxy to syncthing container
location / {
proxy_pass http://xx.xx.xx.xx:1112/;
}
# Redirects to unique syncthing port
location /syncthing {
return 301 https://xx.xx.xx.xx:444/;
}
}
# Syncthing
server {
listen 444 ssl;
server_name xx.xx.xx.xx;
# Reverse proxy to syncthing container
location / {
proxy_pass https://xx.xx.xx.xx:1114/;
}
# Redirects to unique nextcloud port
location /nextcloud {
return 301 https://xx.xx.xx.xx:443/;
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/531604.html
標籤:nginx码头工人撰写nginx-反向代理nginx位置
