Serving a subdirectory

Thomas Schweikle tschweikle at gmail.com
Fri Dec 6 15:47:08 UTC 2019


OK. Trying with a completely different question:

My server serves /var/www/html directory-content as static pages to http://
<server>/

How do I have to set it up to additionally serve http://<server>/chrony
from /var/www/chrony?

I've tried with:
server {
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    server_name nc409-muc.bfs.de;
    root /var/www/chrony;
    index index.sh index.html;

    location / {
        try_files $uri $uri/ $uri/index.sh;
    }

    location ~ "index\.sh$" {
        gzip off;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        include /etc/nginx/fastcgi_params;
        fastcgi_param DOCUMENT_ROOT $document_root;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

But this leads to error 404 - not found.


I've tried with:
server {
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    server_name nc409-muc.bfs.de;
    root /var/www;
    index index.sh index.html;

    location /chrony {
        try_files $uri $uri/ $uri/index.sh;
    }

    location ~ "index\.sh$" {
        gzip off;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        include /etc/nginx/fastcgi_params;
        fastcgi_param DOCUMENT_ROOT $document_root;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

But this also lead to error - 404 - not found.

I did not have success with:
server {
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    server_name nc409-muc.bfs.de;
    root /var/www/chrony;
    index index.sh index.html;

    location ~ "index\.sh$" {
        gzip off;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        include /etc/nginx/fastcgi_params;
        fastcgi_param DOCUMENT_ROOT $document_root;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

lead to 404 - not found.

or

server {
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    server_name nc409-muc.bfs.de;
    root /var/www/chrony;
    index index.sh index.html;

    location ~ "index\.sh$" {
        gzip off;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        include /etc/nginx/fastcgi_params;
        fastcgi_param DOCUMENT_ROOT $document_root;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}

lead to 404 - not found.

But the file is there:
/var/www:
insgesamt 16
drwxr-xr-x  4 root root 4096 Dez  2 16:25 .
drwxr-xr-x 12 root root 4096 Aug 20 12:58 ..
drwxr-xr-x  2 root root 4096 Dez  4 17:17 chrony
drwxr-xr-x  2 root root 4096 Aug 20 12:58 html

/var/www/chrony:
insgesamt 16
drwxr-xr-x 2 root root 4096 Dez  4 17:17 .
drwxr-xr-x 4 root root 4096 Dez  2 16:25 ..
-rw-r--r-- 1 root root   95 Dez  3 13:42 chrony.css
-rwxr-xr-x 1 root root 1712 Dez  3 16:07 index.sh

/var/www/html:
insgesamt 12
drwxr-xr-x 2 root root 4096 Aug 20 12:58 .
drwxr-xr-x 4 root root 4096 Dez  2 16:25 ..
-rw-r--r-- 1 root root  612 Aug 20 12:58 index.nginx-debian.html

and nginx -T does:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

With configuration:
# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

load_module modules/ngx_http_auth_pam_module.so;
load_module modules/ngx_http_dav_ext_module.so;
load_module modules/ngx_http_echo_module.so;
load_module modules/ngx_http_geoip_module.so;
load_module modules/ngx_http_image_filter_module.so;
load_module modules/ngx_http_subs_filter_module.so;
load_module modules/ngx_http_upstream_fair_module.so;
load_module modules/ngx_http_xslt_filter_module.so;
load_module modules/ngx_mail_module.so;
load_module modules/ngx_stream_module.so;

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document
   docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
   xlsx;

application/vnd.openxmlformats-officedocument.presentationml.presentation
 pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;

    return 301 https://$host$request_uri;
}

server {
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    server_name _;

    ssl_certificate      /etc/ssl/certs/nginx.crt;
    ssl_certificate_key  /etc/ssl/private/nginx.key;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location /chrony {
        root /var/www/chrony;
        try_files $uri $uri/ $uri/index.sh;
    }

    location ~ "index\.sh$" {
        gzip off;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        include /etc/nginx/fastcgi_params;
        fastcgi_param DOCUMENT_ROOT $document_root;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
}


# configuration file /etc/nginx/fastcgi_params:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;


On Fri, Dec 6, 2019 at 1:29 PM Francis Daly <francis at daoine.org> wrote:

> On Fri, Dec 06, 2019 at 12:39:59PM +0100, Thomas Schweikle wrote:
>
> Hi there,
>
> This config fails to run for me.
>
> So, unless something very strange is happening, this is not the config
> that your running nginx is actually using.
>
> >     location ~ "index\.sh"$ {
>
> $ sbin/nginx -t
> nginx: [emerg] unexpected "$" in /usr/local/nginx/conf/nginx.conf:19
> nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
> $ sed -n 19p /usr/local/nginx/conf/nginx.conf
>     location ~ "index\.sh"$ {
>
> Changing that line to be
>
>     location ~ "index\.sh$" {
>
> allows it to run.
>
> > For https://<fqdn-server>/:
> > nginx default site delivered ok.
>
> Your provided config says that that should serve something from
> /var/www/chrony. You seem to report that it is serving something from
> /var/www/html.
>
> > For https://<fqdn-server>/chrony:
> > 404 - Not found.
>
> Your provided config says that that should serve something from
> /var/www/chrony/chrony, which I think you show does not exist, so 404
> is correct.
>
> But I suspect that your actual running config is trying to serve something
> from /var/www/html/chrony, which also does not exist, so 404 is created.
>
>
> I think that you will need to identify the actual running config,
> because that will make it easier to make the changes that you want.
>
> Cheers,
>
>         f
> --
> Francis Daly        francis at daoine.org
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>


-- 
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20191206/153a3c68/attachment-0001.htm>


More information about the nginx mailing list