Link to home
Start Free TrialLog in
Avatar of Jasmin shahrzad
Jasmin shahrzad

asked on

nginx website

i have docker image nginx 1.16.0 on ubuntu. i share a volume like that :
 docker run --name my-nginx -v /etc/nginx/nginx-file/nginx.conf:/etc/nginx/nginx.conf -v /etc/nginx/src:/usr/share/nginx/html -p 80:80 nginx:1.16.0

i move all my pages to /etc/nginx/src and they have permission (uid:gid 101:101 and 775) . i can see the file under my image when i login to image.
i can see my index.html file ( <p> hello world </p>) i can't see any file except for index.html
 can't see my jenkins (build."domain") file. What is wrong?
Avatar of noci
noci

1) using /etc as a generic data directory for a starter.
/etc is config only.  If data is need use a /var/lib or /var/www/ ... etc. as /var/ is meant for it.

2) /etc might have more (too restrictive)  access rights.
or uic/uid from the docker are different and won't allow access on the host.

Why your docker doesn't see them in nginx..?   to many variables in this case.
Avatar of Jasmin shahrzad

ASKER

ok when you say var/www do you mean in docker or local. i do not have a www directory in my docker i mean, i should install  fx. appach to have www or what i do not have a many variable in my files. it's jenkin file i want to connect and i get it very standard from jekins site.
its look like i just can see index.html and nothing else.
I won't object, i i won't comment further as well. Asking the right question might have helped.
questionable setup is the first thing that is obvious from the Q.
More information on setup  is needed. Like configured names, does the docker know it's name etc. etc.  
What has been tested to access this etup.
What queries have been tested, what are responses?...
not usable answer
There's two things, that seem to be a little odd to me:
docker run --name my-nginx -v /etc/nginx/nginx-file/nginx.conf:/etc/nginx/nginx.conf -v /etc/nginx/src:/usr/share/nginx/html -p 80:80 nginx:1.16.0
1.) you map /etc/nginx/nginx-files your host to /etc/nginx/
2.) you map /etc/nginx/src to /usr/share/nginx/html

/etc/ on a machine should mostly contain configuration for that machine. and nothing else.

So I'd propose to use something like following
/home/jasmin/nginx_server/conf/nginx.conf to /etc/nginx/nginx.conf
I would map your html files to something like
/home/jasmin/my_nginx_docker/html_files to /usr/share/nginx/html

This in itself will not solve any of your problems, but it might be less confusing for the ones trying to understand your issues.

There's two potential reasons why you don't see your files.
1.) your html direcory does not have the correct permissions. So for a start I propose to render the html directory executable by all and files  readable by all
find /home/jasmin/my_nginx_docker/html_files -type d | xargs chmod a+rx
find /home/jasmin/my_nginx_docker/html_files -type d | xargs chmod a+r

Open in new window


2.) It might be that your config file does not point to the right destination
Could you show us the contents of your config file?


If all this does not work then I propose, to look at the log files of your nginx server.
Either you execute a shell in your docker container and look at the files or you map the log directory  to a volume, such that all log files are visible on your docker host.

Normally you should see clear enough error messages in your log files.


If this still doesn't work, then I can tell you how to increase the debug level in your nginx config to get very verbose traces, that should reveal where the files are searched vs. where they are located.
@gelonida
Thank you
first it was my bad of course i do not map /etc/.../ from my own server . as you wrote i map some home directory to /etc/nginx/... in docker.
i was just copy and paste from my compose file .
the problem is, i do not have a error in my error log. i can see my index.html , and its it.
 I have a simple jenkins file which is working for nginx standalone server, when i move it to nginx in docker, is not working. nothing in error log or access log. permission for directory and all files is 777 and uid:gid is 101:101 (nginx)
  form other session i open command line and    "inotifywait -mrq /containers/nginx| grep OPEN"
when i call jenkins, nothing happen.
could you show the nginx.conf file?

So you say, that access log and error log show nothing? You don't even see a 404?

On the nginx standalone server:
Do you have files in /etc/nginx/sites-enabled, which are configured for serving the jenkins file?


What exactly do you mean with jenkins file?
Normally jenkins is a server and nginx would only act as a  reverse proxy

What url do you use to see the jenkins file on your standaline nginx?
(e.g. http://standaloneserver/jenkins/ )

What url do you use for trying to access the jenkins file on your docker nginx?
this is my nginx.conf

-----
user  nginx;
worker_processes  2;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
    use epoll;
    accept_mutex off;
}


http {
    include       /etc/nginx/mime.types;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    client_max_body_size 300m;
    client_body_buffer_size 128k;
    gzip  on;
    gzip_http_version 1.0;
    gzip_comp_level 6;
    gzip_min_length 0;
    gzip_buffers 16 8k;
    gzip_proxied any;
    gzip_types text/plain text/css text/xml text/javascript application/xml application/xml+rss application/javascript application/json;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;

    include /etc/nginx/conf.d/*.conf;
--------

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial