Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration for NGINX for subfolder #605

Open
hgue opened this issue Aug 24, 2024 · 0 comments
Open

Configuration for NGINX for subfolder #605

hgue opened this issue Aug 24, 2024 · 0 comments

Comments

@hgue
Copy link

hgue commented Aug 24, 2024

Hi,
I try to use the dashboard on a subfolder within my current nginx configuration.
Somehow I cannot get it to work with the location '/admin' as a subfolder path. All other endpoints are working well.
Can anyone help me here? I am not using traefik, so this setup is not helpful for me as explained in the docs.

Here is my current nginx setup:

server {
  listen 443 ssl;
  listen [::]:443 ssl; 
  # For the federation port
  listen 8448 ssl default_server;
  listen [::]:8448 ssl default_server;

  http2 on;
  server_name matrix.example.com;

  ### SSL
  include inc/default_ssl.conf;
  include inc/default_ssl_example.com.conf;

  ### Logging
  access_log /var/log/nginx/matrix.example.com.log;
  error_log /var/log/nginx/matrix.example.com.log;

  ### Nginx
  server_tokens off;
  chunked_transfer_encoding off;

  ### Locations / Routing

  include inc/error_pages.conf;

  location /admin {
    rewrite ^/admin(.*) $1 break;      
    proxy_pass http://10.1.0.36/;
    
    index index.html;
    try_files $uri $uri/ /admin/index.html;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';

    include inc/default_proxy_params.conf; 
  }

  location ~* ^(\/_matrix|\/_synapse\/client) {
    proxy_pass http://10.1.0.30:8008;

    # Nginx by default only allows file uploads up to 1M in size
    # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
    client_max_body_size 50M;
    
    include inc/default_proxy_params.conf;
  }

  location ~ ^/(client/|_matrix/client/unstable/org.matrix.msc3575/sync) {
    proxy_pass http://10.1.0.35:8009;

    include inc/default_proxy_params.conf;
  }

  location /.well-known/matrix/server {
    # Allow access from *
    add_header Access-Control-Allow-Origin '*';
    default_type application/json;
    return 200 '{ "m.server": "matrix.example.com:443" }';
  }

  location /.well-known/matrix/client {
    # Allow access from *
    add_header Access-Control-Allow-Origin '*';
    default_type application/json;
    return 200 '{ "m.homeserver": { "base_url": "https://matrix.example.com" }, "m.identity_server": { "base_url": "https://vector.im" }, "org.matrix.msc3575.proxy": { "url": "https://matrix.example.com" } }';
  }

  # Element.io client
  location / {
    # note: do not add a path (even a single /) after the port in `proxy_pass`,
    # otherwise nginx will canonicalise the URI and cause signature verification
    # errors.
    proxy_pass http://10.1.0.33:80; # container_ip from network for element chat
    # Nginx by default only allows file uploads up to 1M in size
    # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
    client_max_body_size 50M;

    # Content Security Policy (see https://forum.seafile.com/t/content-security-policy/4071)
    add_header "Content-Security-Policy" "default-src 'self'; script-src * 'unsafe-eval' 'wasm-unsafe-eval'; font-src 'self' data:; style-src 'self' 'unsafe-inline' fonts.googleapis.com; child-src * blob: data:; media-src * blob: data:; object-src 'none'; img-src * data: blob:; connect-src * blob:; worker-src * blob:; frame-src * blob: data:";
    # HTTP Strict Transport Security (HSTS)
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;" always; 

    include inc/default_proxy_params.conf;
  }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant