I'm currently running GitLab and an Apache server for Nextcloud on Ubuntu. Everything seems to work fine for a bit, but then it just randomly stops functioning as expected. My GitLab domain directs traffic correctly to GitLab and my Nextcloud domain directs to Apache (which runs on port 8090). However, at some point, it suddenly starts redirecting all the traffic to the Apache server, ignoring both the `server_name` and the `default_server` parameters that I've set up for Nginx.
Here's the configuration I'm using that has worked sporadically. I've noticed that it usually starts functioning again after I rename the configuration file to something else, restart Nginx, and then rename it back to its original name followed by another restart. Here's the relevant part of my Nginx config:
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate [redacted];
ssl_certificate_key [redacted];
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers [redacted];
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
access_log /var/log/nginx/cloud-access.log;
error_log /var/log/nginx/cloud-error.log error;
root /var/www/nextcloud;
server_name example.com;
client_max_body_size 0;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8090;
}
}
3 Answers
The backticks you mentioned are likely due to a formatting issue when pasting your configuration. They shouldn't be there in your actual config file. If you're still stuck, you might want to check forums specific to Nginx or Apache for further insights, and make sure to post your logs for better help.
Have you tried running `nginx -t` to check for errors during the restart? Also, do you see any relevant errors in the Nginx logs? When you mention 'redirect', are you seeing a 301 or 302 that tells you to go to your Nextcloud domain, or does it just display the Nextcloud page without going through the GitLab block? Also, I noticed some backticks in your configuration on the `server_name` entries—what's up with those? They shouldn’t be there unless it’s a formatting error. Also, can you share the GitLab block? By the way, using both Nginx and Apache on the same host seems like overkill. One server should suffice.
It sounds like you're encountering one of Nginx's quirks. Consider using just one `default_server` block with a dummy setting to return a 444 status. You might have several server blocks, which could be conflicting. Try running `nginx -T | grep default_server`, resolve any conflicts, and restart Nginx. That might do the trick!

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures