Question

NGINX reverse proxy to Apache docker container

I’m trying to host several websites on my droplet. I’m to do that, I’m using NGINX (not container) as reverse proxy to Dockerized apps. One such app I’m using is the dockerized Mediawiki set to run on 0.0.0.0:8081.

Mediawiki container is based on php7.2-apache.

Nginx configuration :

server {

        listen 443 ssl;
        index index.php;

        server_name my.website.com;

        ssl_stapling on;
        ssl_stapling_verify on;

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://0.0.0.0:8081;
        }

    ssl_certificate /etc/letsencrypt/live/my.website.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my.website.com/privkey.pem; # managed by Certbot
}

I run the application on port 8081, as can be seen by through docker ps -a

CONTAINER          IMAGE          PORTS
e40c9815d6cc      mediawiki    0.0.0.0:8081 -> 80/tcp

I can access my.website.com, but it shows the default Apache Ubuntu default page. Accessing other pages and resources (index.php, /folder/index.php, images/pic.jpg) returns 404.

Testing the container with similar setup on my machine works. I think there maybe something up I didn’t get with the NGINX config.

Help?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

try to change file in var/www/html put your index.php there…

This comment has been deleted

I had the same issue not too long ago…

you don’t need to open or map 8081 to 80 port for access, just have 80 and 443 ports exposed inside container.

On your nginx container (if you are using docker-compose) add

depends_on: 
- proxied_container

in your nginx.config

proxy_pass http://proxied_container:80;

This way nginx connects to container and its internal port and apache will handle everything else…