{"id":18777891,"url":"https://github.com/aungkohtat/nginx-server","last_synced_at":"2026-04-16T08:31:43.352Z","repository":{"id":217084817,"uuid":"743010244","full_name":"aungkohtat/nginx-server","owner":"aungkohtat","description":"NGINX is open-source web server software used for reverse proxy, load balancing, and caching.","archived":false,"fork":false,"pushed_at":"2024-01-14T07:36:54.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T05:11:41.687Z","etag":null,"topics":["docker","express","nginx","nginx-load-balance","nginx-proxy","npm"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/aungkohtat.png","metadata":{"files":{"readme":"README.md","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,"zenodo":null}},"created_at":"2024-01-14T03:05:36.000Z","updated_at":"2024-01-14T07:45:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"3cf83341-3149-44ba-bf5b-37a448bddae2","html_url":"https://github.com/aungkohtat/nginx-server","commit_stats":null,"previous_names":["aungkohtat/nginx-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aungkohtat/nginx-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aungkohtat%2Fnginx-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aungkohtat%2Fnginx-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aungkohtat%2Fnginx-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aungkohtat%2Fnginx-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aungkohtat","download_url":"https://codeload.github.com/aungkohtat/nginx-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aungkohtat%2Fnginx-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31877479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T07:36:03.521Z","status":"ssl_error","status_checked_at":"2026-04-16T07:35:53.576Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["docker","express","nginx","nginx-load-balance","nginx-proxy","npm"],"created_at":"2024-11-07T20:14:13.281Z","updated_at":"2026-04-16T08:31:43.347Z","avatar_url":"https://github.com/aungkohtat.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003c!-- TOC start (generated with https://github.com/derlin/bitdowntoc) --\u003e\n\n- [nginx-server](#nginx-server)\n   * [nginx installation](#nginx-installation)\n   * [check directory ](#check-directory)\n   * [nginx run localhost](#nginx-run-localhost)\n   * [check nginx.config](#check-nginxconfig)\n   * [nginx static context](#nginx-static-context)\n      + [my new config](#my-new-config)\n   * [mimes type](#mimes-type)\n   * [location block](#location-block)\n   * [redirects and rewrites](#redirects-and-rewrites)\n   * [load balancer](#load-balancer)\n   * [install server setup](#install-server-setup)\n\n\u003c!-- TOC end --\u003e\n\n\u003c!-- TOC --\u003e\u003ca name=\"nginx-server\"\u003e\u003c/a\u003e\n# nginx-server\nNGINX is open-source web server software used for reverse proxy, load balancing, and caching.\n- NGINX is the fastest growing and most popular web server for a reason, so understanding it will be an invaluable skill to anyone working in the web industry, especially network admins \u0026 web developers.\nNGINX is one of the top-grade HTTP Servers which powers most of the top Enterprise websites like Netflix, Dropbox, WordPress, GitHub, Discovery, and many others.\n\u003c!-- TOC --\u003e\u003ca name=\"nginx-installation\"\u003e\u003c/a\u003e\n## nginx installation\n\n```bash\nAungs-MacBook-Pro:~ aungkohtet$ brew install nginx\nRunning `brew update --auto-update`...\n^C\nAungs-MacBook-Pro:~ aungkohtet$ clear\nAungs-MacBook-Pro:~ aungkohtet$ brew install nginx\nRunning `brew update --auto-update`...\n==\u003e Auto-updated Homebrew!\nUpdated 2 taps (homebrew/core and homebrew/cask).\n==\u003e New Formulae\ncsvlens         k8sgpt          rathole         steamguard-cli  zipkin\ndoltgres        kiota           rattler-build   urlscan\nhelm-ls         ncmdump         ruby@3.2        vulkan-volk\n==\u003e New Casks\naqua                ia-presenter        markedit            taccy\nemby                jyutping            prettyclean         wakatime\n\nYou have 7 outdated formulae installed.\n\n==\u003e Downloading https://ghcr.io/v2/homebrew/core/nginx/manifests/1.25.3\n######################################################################### 100.0%\n==\u003e Fetching nginx\n==\u003e Downloading https://ghcr.io/v2/homebrew/core/nginx/blobs/sha256:22ebed3da9b8\n######################################################################### 100.0%\n==\u003e Pouring nginx--1.25.3.sonoma.bottle.tar.gz\n==\u003e Caveats\nDocroot is: /usr/local/var/www\n\nThe default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that\nnginx can run without sudo.\n\nnginx will load all files in /usr/local/etc/nginx/servers/.\n\nTo start nginx now and restart at login:\n  brew services start nginx\nOr, if you don't want/need a background service you can just run:\n  /usr/local/opt/nginx/bin/nginx -g daemon\\ off\\;\n==\u003e Summary\n🍺  /usr/local/Cellar/nginx/1.25.3: 26 files, 2.4MB\n==\u003e Running `brew cleanup nginx`...\nDisable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.\nHide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).\nAungs-MacBook-Pro:~ aungkohtet$\n\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"check-directory\"\u003e\u003c/a\u003e\n## check directory \n- **`cd /usr/local/etc/nginx`**\n\n```bash\nungs-MacBook-Pro:~ aungkohtet$ cd /usr/local/etc/nginx\nAungs-MacBook-Pro:nginx aungkohtet$ ls\nfastcgi.conf\t\tmime.types\t\tservers\nfastcgi.conf.default\tmime.types.default\tuwsgi_params\nfastcgi_params\t\tnginx.conf\t\tuwsgi_params.default\nfastcgi_params.default\tnginx.conf.default\twin-utf\nkoi-utf\t\t\tscgi_params\nkoi-win\t\t\tscgi_params.default\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"nginx-run-localhost\"\u003e\u003c/a\u003e\n## nginx run localhost\n- `http://localhost:8080`\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"check-nginxconfig\"\u003e\u003c/a\u003e\n## check nginx.config\n\n```bash\ncat nginx.conf\n\n#user  nobody;\nworker_processes  1;\n\n#error_log  logs/error.log;\n#error_log  logs/error.log  notice;\n#error_log  logs/error.log  info;\n\n#pid        logs/nginx.pid;\n\n\nevents {\n    worker_connections  1024;\n}\n\n\nhttp {\n    include       mime.types;\n    default_type  application/octet-stream;\n\n    #log_format  main  '$remote_addr - $remote_user [$time_local] \"$request\" '\n    #                  '$status $body_bytes_sent \"$http_referer\" '\n    #                  '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n\n    #access_log  logs/access.log  main;\n\n    sendfile        on;\n    #tcp_nopush     on;\n\n    #keepalive_timeout  0;\n    keepalive_timeout  65;\n\n    #gzip  on;\n\n    server {\n        listen       8080;\n        server_name  localhost;\n\n        #charset koi8-r;\n\n        #access_log  logs/host.access.log  main;\n\n        location / {\n            root   html;\n            index  index.html index.htm;\n        }\n\n        #error_page  404              /404.html;\n\n        # redirect server error pages to the static page /50x.html\n        #\n        error_page   500 502 503 504  /50x.html;\n        location = /50x.html {\n            root   html;\n        }\n\n        # proxy the PHP scripts to Apache listening on 127.0.0.1:80\n        #\n        #location ~ \\.php$ {\n        #    proxy_pass   http://127.0.0.1;\n        #}\n\n        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n        #\n        #location ~ \\.php$ {\n        #    root           html;\n        #    fastcgi_pass   127.0.0.1:9000;\n        #    fastcgi_index  index.php;\n        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;\n        #    include        fastcgi_params;\n        #}\n\n        # deny access to .htaccess files, if Apache's document root\n        # concurs with nginx's one\n        #\n        #location ~ /\\.ht {\n        #    deny  all;\n        #}\n    }\n\n\n    # another virtual host using mix of IP-, name-, and port-based configuration\n    #\n    #server {\n    #    listen       8000;\n    #    listen       somename:8080;\n    #    server_name  somename  alias  another.alias;\n\n    #    location / {\n    #        root   html;\n    #        index  index.html index.htm;\n    #    }\n    #}\n\n\n    # HTTPS server\n    #\n    #server {\n    #    listen       443 ssl;\n    #    server_name  localhost;\n\n    #    ssl_certificate      cert.pem;\n    #    ssl_certificate_key  cert.key;\n\n    #    ssl_session_cache    shared:SSL:1m;\n    #    ssl_session_timeout  5m;\n\n    #    ssl_ciphers  HIGH:!aNULL:!MD5;\n    #    ssl_prefer_server_ciphers  on;\n\n    #    location / {\n    #        root   html;\n    #        index  index.html index.htm;\n    #    }\n    #}\n    include servers/*;\n}\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"nginx-static-context\"\u003e\u003c/a\u003e\n## nginx static context\n\n\u003c!-- TOC --\u003e\u003ca name=\"my-new-config\"\u003e\u003c/a\u003e\n### my new config\n\n```bash\nhttp {\n    server {\n        listen 8080;\n        root /Users/aungkohtet/Documents/akhlab/nginx-server/mysite;\n    }\n}\nevents {}\n```\n\n- `nginx -s reload`\n\n```bash\nAungs-MacBook-Pro:nginx aungkohtet$ nginx -s reload\nAungs-MacBook-Pro:nginx aungkohtet$ Ok\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"mimes-type\"\u003e\u003c/a\u003e\n## mimes type\n- MIME types indicate the nature and format of a document. In NGINX, mime.types assigns these types to file extensions. For example:\n```bash\nhttp {\n    include       mime.types;\n    default_type  application/octet-stream;\n\n    types {\n        text/html                     html htm shtml;\n        text/css                      css;\n        application/javascript        js;\n        image/jpeg                    jpeg jpg;\n        image/png                     png;\n        audio/mpeg                    mp3;\n        // ... more mappings\n    }\n}\n\n```\n\n\n\u003c!-- TOC --\u003e\u003ca name=\"location-block\"\u003e\u003c/a\u003e\n## location block\n- Location blocks define configurations for specific URIs. For instance:\n\n```bash\nserver {\n    location / {\n        root   /path/to/your/files;\n        index  index.html index.htm;\n    }\n\n    location /images/ {\n        alias /path/to/image/files/;\n    }\n}\n\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"redirects-and-rewrites\"\u003e\u003c/a\u003e\n## redirects and rewrites\n- Redirects send an HTTP status code to clients, indicating a resource's move. Rewrites modify URIs internally. Both are crucial for URL manipulation in NGINX.\n\n- Redirect Example:\n\n```bash\nserver {\n    listen 80;\n    server_name old-domain.com;\n    return 301 http://new-domain.com$request_uri;\n}\n\n```\n\n- Rewrite Example:\n\n```bash\nserver {\n    listen 80;\n    server_name example.com;\n\n    location /blog/ {\n        rewrite ^/blog/(.*)$ /posts/$1 last;\n    }\n}\n\n```\n\n\u003c!-- TOC --\u003e\u003ca name=\"load-balancer\"\u003e\u003c/a\u003e\n## load balancer\n\n- NGINX load balancing distributes traffic across multiple servers, enhancing reliability and scalability. The upstream block defines servers, and NGINX balances requests among them.\n\n\u003c!-- TOC --\u003e\u003ca name=\"install-server-setup\"\u003e\u003c/a\u003e\n## install server setup\n- `mkdir server`\n\n- `npm init -y`\n\n```bash\nAungs-MacBook-Pro:server aungkohtet$ npm init -y\nWrote to /Users/aungkohtet/Documents/akhlab/nginx-server/mysite/server/package.json:\n\n{\n  \"name\": \"server\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" \u0026\u0026 exit 1\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\"\n}\n\n\nAungs-MacBook-Pro:server aungkohtet$ \n```\n\n- `npm install express`\n```bash\n\n **package.json add line no.8 \"start\": \"node index\"**\n\n - `npm run start`\n ```bash\n Aungs-MacBook-Pro:server aungkohtet$ npm run start\n\n\u003e server@1.0.0 start\n\u003e node index\n\nListening no port 7777\n ```\n\n **run browser http://localhost:7777**\n\n ## dockerfile for express app\n\n - create dockerfile\n\n ```bash\n # Use an official Node.js runtime as a parent image\nFROM node:16\n\n\u003c!-- TOC --\u003e\u003ca name=\"set-the-working-directory-in-the-container\"\u003e\u003c/a\u003e\n# Set the working directory in the container\nWORKDIR /usr/src/app\n\n\u003c!-- TOC --\u003e\u003ca name=\"copy-packagejson-and-package-lockjson-to-the-working-directory\"\u003e\u003c/a\u003e\n# Copy package.json and package-lock.json to the working directory\nCOPY package*.json ./\n\n\u003c!-- TOC --\u003e\u003ca name=\"install-app-dependencies\"\u003e\u003c/a\u003e\n# Install app dependencies\nRUN npm install\n\n\u003c!-- TOC --\u003e\u003ca name=\"bundle-app-source\"\u003e\u003c/a\u003e\n# Bundle app source\nCOPY . .\n\n\u003c!-- TOC --\u003e\u003ca name=\"expose-port-8080\"\u003e\u003c/a\u003e\n# Expose port 8080\nEXPOSE 8080\n\n\u003c!-- TOC --\u003e\u003ca name=\"define-the-command-to-run-the-app\"\u003e\u003c/a\u003e\n# Define the command to run the app\nCMD [\"npm\", \"run\", \"start\" ]\n\n ```\n\n ```bash\n Aungs-MacBook-Pro:server aungkohtet$ docker build . -t myserver\n[+] Building 185.6s (11/11) FINISHED                                                    docker:desktop-linux\n =\u003e [internal] load .dockerignore                                                                       0.0s\n =\u003e =\u003e transferring context: 2B                                                                         0.0s\n =\u003e [internal] load build definition from Dockerfile                                                    0.0s\n =\u003e =\u003e transferring dockerfile: 493B                                                                    0.0s\n =\u003e [internal] load metadata for docker.io/library/node:16                                              3.9s\n =\u003e [auth] library/node:pull token for registry-1.docker.io                                             0.0s\n =\u003e [1/5] FROM docker.io/library/node:16@sha256:f77a1aef2da8d83e45ec990f45df50f1a286c5fe8bbfb8c6e424  179.2s\n =\u003e =\u003e resolve docker.io/library/node:16@sha256:f77a1aef2da8d83e45ec990f45df50f1a286c5fe8bbfb8c6e4246c  0.0s\n =\u003e =\u003e sha256:f77a1aef2da8d83e45ec990f45df50f1a286c5fe8bbfb8c6e4246c6389705c0b 776B / 776B              0.0s\n =\u003e =\u003e sha256:ffd9397e94b74abcb54e514f1430e00f604328d1f895eadbd482f08cc02444e5 51.89MB / 51.89MB      160.3s\n =\u003e =\u003e sha256:c94b82f9827cab6e421b350965a9ef11b25b13ffbd1030536203d541f55dcbe2 2.00kB / 2.00kB          0.0s\n =\u003e =\u003e sha256:1ddc7e4055fdb6f6bf31063b593befda814294f9f904b6ddfc21ab1513bafa8e 7.23kB / 7.23kB          0.0s\n =\u003e =\u003e sha256:311da6c465ea1576925360eba391bcd32dece9be95960a0bc9ffcb25fe712017 50.50MB / 50.50MB       73.7s\n =\u003e =\u003e sha256:7e9bf114588c05b2df612b083b96582f3b8dbf51647aa6138a50d09d42df2454 17.58MB / 17.58MB       13.1s\n =\u003e =\u003e sha256:513d779256048c961239af5f500589330546b072775217272e19ffae1635e98e 191.90MB / 191.90MB    155.1s\n =\u003e =\u003e extracting sha256:311da6c465ea1576925360eba391bcd32dece9be95960a0bc9ffcb25fe712017               3.9s\n =\u003e =\u003e sha256:ae3b95bbaa61ce24cefdd89e7c74d6fbd7713b2bcae93af47063d06bd7e02172 4.20kB / 4.20kB         74.7s\n =\u003e =\u003e sha256:0e421f66aff42bb069dffc26af6d132194b22a1082b08c5ef7cd69c627783c04 34.79MB / 34.79MB      125.3s\n =\u003e =\u003e extracting sha256:7e9bf114588c05b2df612b083b96582f3b8dbf51647aa6138a50d09d42df2454               0.8s\n =\u003e =\u003e sha256:ca266fd6192108b67fb57b74753a8c4ca5d8bd458baae3d4df7ce9f42dedcc1d 2.27MB / 2.27MB        136.0s\n =\u003e =\u003e sha256:ee7d78be1eb92caf6ae84fc3af736b23eca018d5dedc967ae5bdee6d7082403b 450B / 450B            138.6s\n =\u003e =\u003e extracting sha256:ffd9397e94b74abcb54e514f1430e00f604328d1f895eadbd482f08cc02444e5               4.0s\n =\u003e =\u003e extracting sha256:513d779256048c961239af5f500589330546b072775217272e19ffae1635e98e              11.8s\n =\u003e =\u003e extracting sha256:ae3b95bbaa61ce24cefdd89e7c74d6fbd7713b2bcae93af47063d06bd7e02172               0.0s\n =\u003e =\u003e extracting sha256:0e421f66aff42bb069dffc26af6d132194b22a1082b08c5ef7cd69c627783c04               2.4s\n =\u003e =\u003e extracting sha256:ca266fd6192108b67fb57b74753a8c4ca5d8bd458baae3d4df7ce9f42dedcc1d               0.1s\n =\u003e =\u003e extracting sha256:ee7d78be1eb92caf6ae84fc3af736b23eca018d5dedc967ae5bdee6d7082403b               0.0s\n =\u003e [internal] load build context                                                                       0.1s\n =\u003e =\u003e transferring context: 2.16MB                                                                     0.1s\n =\u003e [2/5] WORKDIR /usr/src/app                                                                          0.6s\n =\u003e [3/5] COPY package*.json ./                                                                         0.0s\n =\u003e [4/5] RUN npm install                                                                               1.7s\n =\u003e [5/5] COPY . .                                                                                      0.1s\n =\u003e exporting to image                                                                                  0.1s\n =\u003e =\u003e exporting layers                                                                                 0.1s\n =\u003e =\u003e writing image sha256:f8be430929e6a20e619e860a3b608ea9efe26b17fc4189177c6c9362fe1a246c            0.0s\n =\u003e =\u003e naming to docker.io/library/myserver                                                             0.0s\n\nWhat's Next?\n  View a summary of image vulnerabilities and recommendations → docker scout quickview\n ```\n\n - `docker run -p 1111:7777 -d myserver`\n\n ```bash\n Aungs-MacBook-Pro:server aungkohtet$ docker run -p 1111:7777 -d myserver\n85e581302371c38ace3b87d2b807d647cfff05e5c7f072dad2d7502256cb9220\nAungs-MacBook-Pro:server aungkohtet$ docker run -p 2222:7777 -d myserver\n1403106b63f8a49e52feabddb6fd2702ee4624315e3212c2f9d49bc2448a57bd\nAungs-MacBook-Pro:server aungkohtet$ docker run -p 3333:7777 -d myserver\n4c046f176b432da408dd421afbc678f08e6faba139b7adbb99be0e75cabfa507\nAungs-MacBook-Pro:server aungkohtet$ \n ```\n\n **run browser http://localhost:1111, http://localhost:2222, http://localhost:3333, http://localhost:4444**\n\n ```bash\n Aungs-MacBook-Pro:server aungkohtet$ docker ps\nCONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS                              NAMES\n8b875e7c4897   myserver   \"docker-entrypoint.s…\"   13 minutes ago   Up 13 minutes   8080/tcp, 0.0.0.0:4444-\u003e7777/tcp   bold_bardeen\n4c046f176b43   myserver   \"docker-entrypoint.s…\"   14 minutes ago   Up 14 minutes   8080/tcp, 0.0.0.0:3333-\u003e7777/tcp   infallible_brahmagupta\n1403106b63f8   myserver   \"docker-entrypoint.s…\"   15 minutes ago   Up 15 minutes   8080/tcp, 0.0.0.0:2222-\u003e7777/tcp   admiring_heyrovsky\n85e581302371   myserver   \"docker-entrypoint.s…\"   15 minutes ago   Up 15 minutes   8080/tcp, 0.0.0.0:1111-\u003e7777/tcp   funny_solomon\nAungs-MacBook-Pro:server aungkohtet$ \n ```\n\n\n\n\n\n  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faungkohtat%2Fnginx-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faungkohtat%2Fnginx-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faungkohtat%2Fnginx-server/lists"}