Docker, Discourse and Nginx

Posted March 10, 2015 5.9k views

Base problem here is, I’m trying to set Discourse up in a droplet to serve comment threads for a site that is hosted elsewhere (as well as create a community). I’ve been getting CORS-related 403 errors because of this setup (you can see discussion regarding the issue here:

I’ve ended up determining nginx to be the next thing to try and work on. Problem is, nginx is running within a Docker app, and as a consequence editing it directly would only work as a temporary workaround (I’d need to fix every time I rebuild my app).

I wanna include this ( in nginx’s configuration, at building stage (in other words, I need to figure out how to get Docker to include this configuration in the nginx instance it includes in the app). Problem is I know next to nothing about YAML and Docker, so I have no idea where to act. Any pointers?

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.

Submit an Answer
1 answer

There are multiple ways to accomplish what you want to do. Could you provide any more information about how you are running Nginx with Docker? Are you building an image from your own Dockerfile?

Often you would copy the configuration files into the image while building it. Another approach is to bind mount a directory on the host system into the container. Assuming you are using the official Nginx Docker image directly, you could do something like:

docker run --name your-nginx-container -v /local/path/to/nginx.conf.d:/etc/nginx/conf.d:ro -p 80:8080 -d nginx

Where /local/path/to/nginx.conf.d is a directory in the host filesystem. You can then drop additional Nginx configuration files into that directory and they will be used inside of the container. For Nginx to pick up the new configuration, you’ll need to restart the process with:

docker restart your-nginx-container