Rocket.Chat under Subdirectory NGINX

Hello All,

I’m installing Rocket.Chat alongside my Nextcloud installation under a subdirectory so I would have:

https://my_domain -> as my usual Nextcloud
https://my_domain/rocketchat -> as my Rocket.Chat instance

The thing is I cannot avoid NGINX re-direction to the main page even though I manually place the /rocketchat in my domain, do you have any ideas why?

Nextcloud NGINX config file:
server {
listen 80 default_server;
server_name MY_DOMAIN;
location ^~ /.well-known/acme-challenge {
proxy_pass http://127.0.0.1:81;
proxy_set_header Host $host;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2 default_server;
server_name MY_DOMAIN;
root /var/www/nextcloud/;
access_log /var/log/nginx/nextcloud.access.log main;
error_log /var/log/nginx/nextcloud.error.log warn;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
client_max_body_size 10240M;
location / {
rewrite ^ /index.php$uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ .(?:flv|mp4|mov|m4a)$ {
mp4;
mp4_buffer_size 5m;
mp4_max_buffer_size 10m;
fastcgi_split_path_info ^(.+.php)(/.)$;
include fastcgi_params;
include php_optimization.conf;
fastcgi_pass php-handler;
fastcgi_param HTTPS on;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+).php(?:$|/) {
fastcgi_split_path_info ^(.+.php)(/.
)$;
include fastcgi_params;
include php_optimization.conf;
fastcgi_pass php-handler;
fastcgi_param HTTPS on;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~ .(?:css|js|woff|svg|gif|png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
access_log off;
expires 30d;
}
}

Rocket.Chat NGINX config file:
upstream backend {
server 127.0.0.1:3000;
}
server {
listen 443 ssl;
server_name MY_DOMAIN;
error_log /var/log/nginx/rocketchat.access.log;
location /rocketchat {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://127.0.0.1:3000/rocketchat;
proxy_redirect off;
}
location /file-upload/ {
proxy_pass http://127.0.0.1:3000/chat/file-upload/;
}
}

Any hint will be appreciated!

Thanks a lot!

Cheers,
Bruno.