How to configure nginx to work with answer on docker?

Viewed 667

I can't install ANSWER on AWS.
Can someone help me please, thank u.

2 Answers

Installing & Configuring nginx

1. Installing nginx

ANSWER by default runs on port 9080, meaning that by default you must access it using a port number in addition to the hostname (e.g. http://example.org:9080)

In order to allow ANSWER to be served without a port, nginx can be set up to proxy all requests to a particular hostname (or subdomain) to an upstream ANSWER server running on any port.

> sudo apt-get install -y nginx

Verify the installation of nginx

> nginx -v

and that the service will run

> sudo systemctl start nginx
> sudo systemctl status nginx

You should now be able to go to your site's address in your browser and see the default Welcome to nginx! message.

2. Configuring nginx

NGINX-served sites are contained in a server block which are normally stored in separate files from the main nginx config (which is very rarely edited).

When installing with the ppa above, the best way to install new nginx configs is to add new files in /etc/nginx/sites-available (like /etc/nginx/sites-available/example.org). You then must link these files from sites-available to sites-enabled.

The following demonstrates a typical series of commands when creating a new nginx config:

> cd /etc/nginx/sites-available
> sudo nano example.com # config entered into file and saved
> cd ../sites-enabled
> sudo ln -s ../sites-available/example.com

Below is an example configuration for ANSWER running on port 9080.

server {
    listen 80;

    server_name www.example.com example.com;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:9080;
        proxy_redirect off;

        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

After making changes to nginx configs, you have to reload the service for changes to take effect:

> sudo systemctl reload nginx

For more information, go to the configuring nginx page.

If using docker, there is no need to manually install and configure Nginx.

Instead, you should use Nginx Proxy Manager via docker. Its a tool that allows you to map whatever domain to whatever service or url. Super easy, does not require manual tinkering, is set up in minutes and works absolutely flawless. It can also generate ssl certificates (and auto-updates them) and has other life changing features.

Here is the docker compose file:

version: '3.8'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt