a year ago
Hello,
My app is running on Railway using php:8.2-apache. I've configured Apache to listen on port 8080 and included EXPOSE 8080 in the Dockerfile, as this seems to align better with Railway's setup.
However, I'm encountering a strange issue: some redirects in production occasionally include :8080 in the URL (e.g., https://myapp.com:8080/...). This doesn't happen consistently — most URLs are fine, but certain routes at certain times show this incorrect port, which breaks the redirect or causes routing errors.
I've explicitly set the base URL in my environment variables (CI_APP_BASEURL=https://myapp.com) and enabled forced HTTPS in my app config. Everything works perfectly in development — this only occurs in Railway's production environment.
Could you help me understand what might be causing this and how to prevent the port from leaking into public URLs?
Thanks,
S.
6 Replies
a year ago
Just a quick follow-up to my previous message:
In my app, the URLs are correctly defined — I’m clicking on links like https://myapp.com/... and there’s no mention of port 8080 anywhere in my code or config.
However, when inspecting the network traffic (via browser dev tools), I notice that some of these requests hang for 50–60 seconds, and then result in a redirect to https://myapp.com:8080/..., which fails to load.
This only happens on certain URLs and at unpredictable times, making it very hard to reproduce consistently, but it’s clearly coming from the platform’s behavior, not the application code.
Thanks again for your help,
a year ago
Hmmm, on your apache config, can you try adding:
```
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 0.0.0.0/0
SetEnvIf X-Forwarded-Proto "https" HTTPS=on
```
Status changed to Awaiting User Response Railway • 11 months ago
a year ago
Hey,
0.0.0.0/0 is not possible (Apache error), so I put this, but still doesn't work 

```
# Enable RemoteIP mod
RUN a2enmod remoteip
# Config mode
RUN echo 'RemoteIPHeader X-Forwarded-For\n\
RemoteIPInternalProxy 10.0.0.0/8\n\
RemoteIPInternalProxy 172.16.0.0/12\n\
SetEnvIf X-Forwarded-Proto "https" HTTPS=on' \
> /etc/apache2/conf-available/remoteip.conf \
&& a2enconf remoteip
```
Same issue. Do you have any other idea?
Status changed to Awaiting Railway Response Railway • 11 months ago
a year ago
Hey kaleidoscopique, picking up for Angelo.
Definitely something is happening where Apache is not handling traffic properly in some scenarios when coming through Railway's proxy.
First: Can you share your full apache config and Dockerfile? That will help me debug.
I think I want to look at X-Forwarded-Proto, X-Forwarded-Host, and X-Forwarded-Port headers first, then look at ensuring we're handling all the RemoteIPInternalProxy proxy headers correctly.
Other ideas:
```
# Prevent port from leaking into redirects
RequestHeader set X-Forwarded-Port "443"
RequestHeader set X-Forwarded-Proto "https"
# Use X-Forwarded-Host for ServerName
UseCanonicalName Off
```
Status changed to Awaiting User Response Railway • 11 months ago
10 months ago
Hello! Thanks a lot for your help.
I’ve restructured my deployment to remove Apache entirely, switching to a simple setup using the built-in PHP CLI server (php -S 0.0.0.0:8080 -t public).
Since making this change:
All redirects are now working properly.
There are no more unwanted
:8080ports leaking into URLs.The app behaves consistently, with no proxy-related issues.
In the end, I realized I didn’t actually need Apache for my project’s requirements, and using PHP’s native server fits my Railway deployment much more smoothly.
But FYI, I can share my old entrypoint : https://pastebin.com/B4ZgiSMC
and my old dockerfile : https://pastebin.com/4Ma3GUhJ
Nothing fancy, but if you have any idea about why it didn't work, I'm really curious.
Thanks again! Have a nice day.
Status changed to Awaiting Railway Response Railway • 11 months ago
10 months ago
I think you were seeing routing issues with how Apache was configured. Glad to hear you were able to work around the issue!
Status changed to Awaiting User Response Railway • 11 months ago
Status changed to Solved echohack • 11 months ago