{"id":22886945,"url":"https://github.com/itsawa/book_hosting","last_synced_at":"2025-03-31T19:13:14.006Z","repository":{"id":260366898,"uuid":"860916723","full_name":"ITSawa/Book_Hosting","owner":"ITSawa","description":"Simple service to host and lead the books (pages by pages)","archived":false,"fork":false,"pushed_at":"2024-10-09T06:12:02.000Z","size":14473,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T23:29:43.907Z","etag":null,"topics":["books","collection","hosting","page","pages","server","service","site","webapp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ITSawa.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-21T14:08:50.000Z","updated_at":"2024-12-05T19:31:55.000Z","dependencies_parsed_at":"2024-10-30T23:42:47.975Z","dependency_job_id":null,"html_url":"https://github.com/ITSawa/Book_Hosting","commit_stats":null,"previous_names":["itsawa/book_hosting"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FBook_Hosting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FBook_Hosting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FBook_Hosting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ITSawa%2FBook_Hosting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ITSawa","download_url":"https://codeload.github.com/ITSawa/Book_Hosting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246523874,"owners_count":20791444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["books","collection","hosting","page","pages","server","service","site","webapp"],"created_at":"2024-12-13T20:28:51.764Z","updated_at":"2025-03-31T19:13:13.979Z","avatar_url":"https://github.com/ITSawa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"README\nOverview\nThis project sets up an Nginx server to host static files and proxy requests to a Docker container running the backend. The backend is launched using Docker Compose, which also starts up PostgreSQL and the backend service.\n\nPrerequisites\nDocker\nDocker Compose\nNginx\nInstallation and Setup\nStep 1: Clone the Repository\nbash\n \ngit clone \u003crepository-url\u003e\ncd \u003crepository-directory\u003e\nStep 2: Create a .env File\nCreate a .env file in the root directory of backend, filling in the placeholder values:\n\n.env\n\nACCESS_SECRET=''\nREFRESH_SECRET=''\nCOOKIE_SIGN=''\n\nPG_LOGIN=''\nPG_PASS=''\nPG_HOST=''\nPG_PORT=''\nPG_NAME=''\n\n\nStep 3: Build and Run the Docker Containers\nTo build and run the Docker containers, use the following command:\n\nbash\n \ndocker-compose up --build\n--build is required the first time you run the containers or if you make changes to the Dockerfile.\nStep 4: Configure Nginx\nEnsure that Nginx is properly configured to serve static files from the build directory and proxy API requests to the backend. Here is the Nginx configuration:\n\nnginx\n \nuser www-data;\nworker_processes auto;\npid /run/nginx.pid;\n\nevents {\n    worker_connections 1024;\n}\n\nhttp {\n    include /etc/nginx/mime.types;\n    default_type application/octet-stream;\n\n    types {\n        text/css css;\n        text/javascript js;\n        application/javascript js;\n        application/json json;\n        image/jpeg jpg jpeg;\n        image/png png;\n        application/font-woff2 woff2;\n        application/font-woff woff;\n        application/x-font-ttf ttf;\n        font/opentype otf;\n        application/x-font-otf otf;\n        image/svg+xml svg svgz;\n        application/x-font-ttf ttf;\n    }\n\n    server {\n        listen 80;\n\n        root /home/savely/Documents/projects/hostings/books_hosting/frontend/build;\n\n        index index.html;\n\n        location /static/ {\n            alias /home/savely/Documents/projects/hostings/books_hosting/frontend/build/static/;\n            expires 30d;\n            add_header Cache-Control \"public\";\n        }\n\n        location /backend/ {\n            rewrite ^/backend/(.*)$ /$1 break;\n            proxy_pass http://localhost:3001;\n            proxy_set_header Host $host;\n            proxy_set_header X-Real-IP $remote_addr;\n            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n            proxy_set_header X-Forwarded-Proto $scheme;\n            proxy_http_version 1.1;\n            proxy_set_header Connection \"\";\n            proxy_set_header Upgrade $http_upgrade;\n            proxy_set_header Connection \"upgrade\";\n        }\n\n        location / {\n            try_files $uri /index.html;\n        }\n    }\n}\nMake sure to replace /home/savely/Documents/projects/hostings/books_hosting/frontend/build with the actual path to your build directory.\n\nStep 5: Start Nginx\nStart or reload the Nginx server to apply the new configuration:\n\nbash\n\nsudo service nginx start\n# or\nsudo service nginx reload\nDocker Compose Configuration\nHere is the docker-compose.yml file:\n\nyaml\n \nversion: '3.8'\n\nservices:\n  backend:\n    build:\n      context: ./backend\n    ports:\n      - \"3001:3001\"\n    environment:\n      - NODE_ENV=development\n      - PG_HOST=postgres_db\n      - PG_PORT=5432\n      - PG_USER=${POSTGRES_USER}\n      - PG_PASS=${POSTGRES_PASSWORD}\n      - PG_NAME=${POSTGRES_DB}\n    depends_on:\n      - postgres_db\n\n  postgres_db:\n    image: postgres:13\n    volumes:\n      - postgres_data:/var/lib/postgresql/data\n    environment:\n      - POSTGRES_USER=${POSTGRES_USER}\n      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}\n      - POSTGRES_DB=${POSTGRES_DB}\n    ports:\n      - \"5432:5432\"\n\nvolumes:\n  postgres_data:\nNotes\nMake sure to replace placeholders (e.g., POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB) with actual values.\nEnsure that the backend service in Docker Compose is configured to connect to the PostgreSQL container using the correct environment variables.\nUsage\nOnce everything is set up, you can access the frontend by navigating to your server's address (e.g., http://yourdomain.com). The backend can be accessed through the /backend/ endpoint (e.g., http://yourdomain.com/backend/).\n\nConclusion\nThis project sets up an Nginx server to serve static files and proxy API requests to a backend running in Docker. The backend and PostgreSQL database are managed using Docker Compose. Follow the steps above to get started with the setup and configuration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Fbook_hosting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsawa%2Fbook_hosting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsawa%2Fbook_hosting/lists"}