I want to view a specific file when I get access to a specific URL.

Asked 2 years ago, Updated 2 years ago, 37 views

Prerequisites/What you want to achieve

I would like to see /var/www/html/hoge/fuga/index.html of the nginx file system when I get access at http://localhost:8080/fuga.I would appreciate it if you could let me know if you know.

Problems/Error Messages you are experiencing

http://localhost:8080/fuga does not know how to properly write location when accessed.

Source Codes Affected

project
├-- docker-compose.yml
├-- Dockerfile
├-- nginx
│   --default.conf
└-- app
    └-- html
        ├-- hoge
        │     --fuga
        │          ----index.html
        └-- index.html

project/docker-compose.yml

version:"3"

services:
    app:
        build:
            context:.
        volumes:
            - ./app: /var/www
        ports:
            - "8080:80"

project/Dockerfile

 FROM nginx:1

WORKDIR/var/www/html

COPY./app/var/www/html
COPY./nginx/default.conf/etc/nginx/conf.d/default.conf

project/nginx/default.conf

server{
    listen80;
    listen [::]:80;
    server_name localhost;

    root/var/www/html/;
}

project/app/html/hoge/fuga/index.html

hogefuga

project/app/index.html

index

Verification Methods

http://localhost:8080/fuga you want to see hogefuga.

nginx

2022-09-29 21:54

1 Answers

Added the following to default.conf:

server{
  listen80;
  listen [::]:80;
  server_name localhost;

  root/var/www/html/;

+  location/fuga{
+    root/var/www/html/hoge;
+  }
}


2022-09-29 21:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.