NGINX SErver setup with include

Issue #67 resolved
Chris Hird created an issue

Tried to set up NGINX Server using the include option.

I have set up 2 directories under /QOpenSys/etc/nginx (sites-available and sites-enabled

I created a config file call mytest.shield.local in sites-available with the following content.

server {
    listen 80;
    server_name mytest.shield.local;

    root /www/php/htdocs/mytest;
    index index.html index.php;
    # pass PHP scripts to FastCGI server
    location ~ \.php$ {
        include /QOpenSys/etc/nginx/snippets/fastcgi-php.conf;
        fastcgi_pass php;
    }

    location / {
        try_files $uri $uri/ =404;
    }
}

I then added a link in sites-enabled to that file called mytest.shield.local

In the nginx.conf file I added an include statement as follows

include /QOpenSys/etc/nginx/sites-enabled/*;

This should have loaded the server config in the appropriate place. However when I run the server I do not get any content served? If I remove the include statement and paste in the same content as the mytest.shield.local file it serves the content as expected.

Comments (7)

  1. mengxumx Account Deactivated

    I can not recreate the issue with nginx version: nginx/1.15.2 --

    • Create the symbolic link
    [xumeng@ut25bp17 nginx]$ ls -l sites-enabled/
    total 4
    lrwxrwxrwx 1 xumeng 0 110 Mar 21 08:21 mytest.shield.local -> /QOpenSys/etc/nginx/sites-available/mytest.shield.local
    
    • Include sites-enabled/mytest.shield.local in test.conf but a wrong place. Obivously nginx finds the physical file of the symbolic link and detects the error.
    [xumeng@ut25bp17 nginx]$ nginx -c ./test.conf
    nginx: [emerg] "server" directive is not allowed here in /QOpenSys/etc/nginx/sites-enabled/mytest.shield.local:1
    
    • Put the include /QOpenSys/etc/nginx/sites-enabled/*; directive in the right place and rerun nginx. The page can be served correctly at port 12580.
    cat test.conf
    html {
        include /QOpenSys/etc/nginx/sites-enabled/*;
        server {
            #listen       12580;
        }
    
    cat sites-available/mytest.shield.local
    server {
      listen  12580;
    }
    

  2. mengxumx Account Deactivated

    Also tested with the latest nginx version: nginx/1.16.1 , still no problem.

    So nginx could find the real path of symbolic links. Maybe it is a configuration context issue?

  3. Chris Hird reporter

    Sorry I have removed the setup sometime ago due to this and other issues. When I get time I will get back to testing again and update the problem. If you wish you can close this out and I will re-open should it be necessary..

  4. Log in to comment