Bug 918351

Summary: Update broke include configuration
Product: [Fedora] Fedora Reporter: Renich Bon Ciric <renich>
Component: nginxAssignee: Nobody's working on this, feel free to take it <nobody>
Status: CLOSED WORKSFORME QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 18CC: jeremy
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-03-26 13:54:14 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Set of configuration files that are working
none
Working configuration none

Description Renich Bon Ciric 2013-03-06 03:14:51 UTC
Description of problem:
when I updated to:

===============================================================================
  nginx-1.2.7-2.fc18
===============================================================================
  Update ID : FEDORA-2013-2974
    Release : Fedora 18
       Type : security
     Status : stable
     Issued : 2013-02-24 07:41:31
       Bugs : 913724 - Rename manual deployment chapters to be more consistent.
	    : 913735 - nginx: world-readable log files [fedora-all]
Description : Make sure nginx directories are not world readable
  Installed : false

it broke my include configurations. localhost works fine but not the rest.

Version-Release number of selected component (if applicable):
1:1.2.7-2.fc18

How reproducible:
add this to your nginx.conf

    include /etc/nginx/sites.d/*.conf

create that dir:

    mkdir /etc/nginx/sites.d

and add this configuration:
    # /etc/nginx/sites.d/zendframework.conf
    server {
        listen 80;
        server_name ~^(?<domain>.+)\.zf\.local$;
        root /srv/www/zendframework/$domain/default/public;
        index /index.php;

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

        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            # Some basic cache-control for static files to be sent to the browser
            expires -1;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }    

        location = /robots.txt { access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }
        location ~ /\. { access_log off; log_not_found off; allow all; }
        location ~ ~$ { access_log off; log_not_found off; deny all; }

        location ~ \.php {
            fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;

            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param APPLICATION_ENV development;

            include /etc/nginx/fastcgi_params;
        }
    }

And, also, this:
    # /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  SCRIPT_FILENAME    $document_root$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  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;

Steps to Reproduce:
1. do the configuration

2. create a default project: 
    cd /srv/www/zendframework/
    zf create project default

3. try it on 1.2.5. Go to: http://default.zf.local/

3. update to 1.2.7

4. try again
  
Actual results:
404 error and nothing on the nginx log even when set to debug on the log level.

Expected results:
It should work

Additional info:
I am using php-fpm configured to use sockets and not the 9000 port. The socket configuration is straight forward:

    # /etc/php-fpm.d/www.conf
    ...
    listen = /run/php-fpm/php-fpm.sock
    ...
    ;listen.allowed_clients = 127.0.0.1
    ...
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660

Comment 1 Jamie Nguyen 2013-03-06 06:42:28 UTC
Thanks for reporting. Can you run this and post the output please?

  nginx -t

And run these too and post the output.

  systemctl start nginx
  systemctl status nginx

Comment 2 Renich Bon Ciric 2013-03-06 09:51:54 UTC
Thanks for the swift response.

Here's the output you wnated:

    [root@introdeskg02org ~]# yum upgrade 
    Loaded plugins: fastestmirror, langpacks, merge-conf, presto, refresh-packagekit, remove-with-leaves, security, show-leaves, verify
    Loading mirror speeds from cached hostfile
     * fedora: mirror.nexcess.net
     * rpmfusion-free: mirror.nexcess.net
     * rpmfusion-free-updates: mirror.nexcess.net
     * rpmfusion-nonfree: mirror.nexcess.net
     * rpmfusion-nonfree-updates: mirror.nexcess.net
     * updates: dl.fedoraproject.org
    Resolving Dependencies
    --> Running transaction check
    ---> Package nginx.x86_64 1:1.2.5-1.fc18 will be updated
    ---> Package nginx.x86_64 1:1.2.7-2.fc18 will be an update
    --> Finished Dependency Resolution

    Dependencies Resolved

    ===================================================================================================================================================================================================================
     Package                                         Arch                                             Version                                                  Repository                                         Size
    ===================================================================================================================================================================================================================
    Updating:
     nginx                                           x86_64                                           1:1.2.7-2.fc18                                           updates                                           425 k

    Transaction Summary
    ===================================================================================================================================================================================================================
    Upgrade  1 Package

    Total download size: 425 k
    Is this ok [y/N]: y
    Downloading Packages:
    Setting up and reading Presto delta metadata
    nginx-1.2.7-2.fc18.x86_64.rpm                                                                                                                                                               | 425 kB  00:00:03     
    Running Transaction Check
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Updating   : 1:nginx-1.2.7-2.fc18.x86_64                                                                                                                                                                     1/2 
    warning: /etc/nginx/nginx.conf created as /etc/nginx/nginx.conf.rpmnew
      Cleanup    : 1:nginx-1.2.5-1.fc18.x86_64                                                                                                                                                                     2/2 

    Package nginx: merging configuration for file "/etc/nginx/nginx.conf":
    By default, RPM would keep your local version and rename the new one to /etc/nginx/nginx.conf.rpmnew
    What do you want to do ?
     - diff the two versions (d)
     - do the default RPM action (q)
     - install the package's version (i)
     - merge interactively with meld (m)
     - merge interactively with vim (v)
     - background this process and examine manually (z)
    Your answer ? q
    Choosing RPM's default action.
      Verifying  : 1:nginx-1.2.7-2.fc18.x86_64                                                                                                                                                                     1/2 
      Verifying  : 1:nginx-1.2.5-1.fc18.x86_64                                                                                                                                                                     2/2 

    Updated:
      nginx.x86_64 1:1.2.7-2.fc18                                                                                                                                                                                      

    Complete!
    [root@introdeskg02org ~]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    [root@introdeskg02org ~]# systemctl restart nginx.service 
    [root@introdeskg02org ~]# systemctl status nginx.service
    nginx.service - The nginx HTTP and reverse proxy server
	      Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
	      Active: active (running) since Wed 2013-03-06 03:50:31 CST; 4s ago
	     Process: 14266 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
	     Process: 14273 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
	     Process: 14270 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
	    Main PID: 14274 (nginx)
	      CGroup: name=systemd:/system/nginx.service
		      ├─14274 nginx: master process /usr/sbin/nginx
		      └─14275 nginx: worker process

    Mar 06 03:50:31 introdeskg02org systemd[1]: Starting The nginx HTTP and reverse proxy server...
    Mar 06 03:50:31 introdeskg02org nginx[14270]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    Mar 06 03:50:31 introdeskg02org nginx[14270]: nginx: configuration file /etc/nginx/nginx.conf test is successful
    Mar 06 03:50:31 introdeskg02org systemd[1]: Started The nginx HTTP and reverse proxy server.

Comment 3 Jamie Nguyen 2013-03-06 18:01:44 UTC
Thanks for the above.

Ok, I couldn't quite figure out how to get your configs working, so I did these steps instead (with all default settings for nginx/php.ini/php-fpm/zend unless otherwise stated):

1) rm -rf /etc/nginx
2) yum remove nginx
3) yum install nginx-1.2.5-1.fc18


4) Add this to /etc/nginx/nginx.conf:

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


5) Add this to /etc/nginx/fastcgi_params:

  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


6) /etc/php-fpm.d/www.conf should have this:

  ;listen = 127.0.0.1:9000
  listen = /run/php-fpm/php-fpm.sock
  ;listen.allowed_clients = 127.0.0.1
  listen.owner = nginx
  listen.group = nginx
  listen.mode = 0666


7) Create /etc/nginx/conf.d/zendframework.conf with this contents:

server {
    listen 80;
    server_name test.com;
    root /srv/www/zendframework/default/public;
    index /index.php;
    location / {
        try_files $uri $uri/ /index.php;
    }
    location ~ \.php {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param APPLICATION_ENV development;
        include /etc/nginx/fastcgi_params;
    }
}


8) rm -rf /srv/www
   mkdir -p /srv/www/zendframework
   zf create project default

9) Add this to /etc/hosts: 127.0.0.1 test.com

10) Browse to http://test.com and see "Welcome to the Zend Framework" page

11) yum update nginx

12) systemctl restart nginx

13) Browser to http://test.com and see "Welcome to the Zend Framework" page


So the above steps let me see the Zend welcome page on both versions of nginx. It would perhaps be good if you could repeat these steps yourself up to step 13, then alter the nginx/php/zend configs in small steps (while testing) until they reach your current setup. We can then see if there's a particular option or configuration or whatever that's causing the problem because I'm not sure how else to debug.

Comment 4 Jamie Nguyen 2013-03-06 18:05:50 UTC
Oops, I'm sure you realise but step 8 should look like this:

8) rm -rf /srv/www
   mkdir -p /srv/www/zendframework
   cd /srv/www/zendframework
   zf create project default

Comment 5 Renich Bon Ciric 2013-03-08 08:34:35 UTC
Hello, Jamie,

As you said, it works the way you configured it but not quite. You forgot to change the unix: in the zendframework.conf; which it didn't matter since I didn't restart php-fpm and it kept offering the socket at /run/php-fpm/php-fpm.sock

Anyway, I've pinpointed the problem.

# doesn't work on 1.2.7 and it does in 1.2.5
server_name ~^(?<domain>.+)\.zf\.g02\.org$;

That does a simple thing. It let's me have a domian (g02.org) and define several configurations; let's say:

zendframework zf.g02.org
wordpress wp.g02.org
drupal dp.g02.org
mediawiki wk.g02.org

And have specific configuration options for them. The "dynamic" part of it, finds the document root based on subdomain 2; for example:

# default.zf.g02.org  -> /srv/www/zendframework/default/public
# somesite.zf.g02.org -> /srv/www/zendframework/somesite/public
# default.wp.g02.org -> /srv/www/wordpress/default/public
...

This is very useful in combination with a wildcard local dns that points *.g02.org to 127.0.0.1. It lets me create projects just by creating the directory structure and putting the files there.

Anyway, it seems that the regex part of it is broken. The same line (the regex one) works on the past version.

This is definitely a bug in that place worth reporting upstream IMHO.

Try it with your setup on 1.2.5 and 1.2.7. Just change the server_name line from:

server_name test.com;

to:

server_name ~^(?<domain>.+)\.zf\.test.com$;

and add this to /etc/hosts:

127.0.0.1    default.zf.test.com
127.0.0.1    somesite.zf.test.com

Then, just try both. I'd recommend creating zendframework only on the first one, the other one should contain an index.php file containing "I'm the other site" or something...

p.s. sorry for the delay but had to go to the hospital 'cause my brother got some really painful kidney stones and had to be operated.

Comment 6 Renich Bon Ciric 2013-03-08 08:36:47 UTC
Ok, wait, there are 2 lines to replace:

    server_name ~^(?<domain>.+)\.zf\.g02\.org$;
    root /srv/www/zendframework/$domain/default/public;

$domain gets replaced by whatever you have as subdomain2.

Comment 7 Jamie Nguyen 2013-03-08 09:49:38 UTC
Created attachment 706962 [details]
Set of configuration files that are working

> As you said, it works the way you configured it but not quite.
> You forgot to change the unix: in the zendframework.conf; which
> it didn't matter since I didn't restart php-fpm and it kept
> offering the socket at /run/php-fpm/php-fpm.sock

Sorry, it's possible I'm being completely dense here (no coffee yet) but I'm not sure what you mean? From comment #3 I have:

/etc/php-fpm.d/www.conf:
listen = /run/php-fpm/php-fpm.sock

/etc/nginx/conf.d/zendframework.conf:
fastcgi_pass unix:/run/php-fpm/php-fpm.sock


> p.s. sorry for the delay but had to go to the hospital 'cause
> my brother got some really painful kidney stones and had to be
> operated.

No problem. Hope he's feeling better.


Anyway, I've attached the set of configs I have. zendframework.conf uses the <domain> thingy and it seems to work on both nginx 1.2.5 and 1.2.7 when I access default.zf.local (gives me welcome to zf page) and somesite.zf.local (gives my phpinfo page). It would again be helpful if you could test those configs I've attached.

Comment 8 Renich Bon Ciric 2013-03-08 09:56:27 UTC
(In reply to comment #7)
> Created attachment 706962 [details]
> Set of configuration files that are working
> 
> > As you said, it works the way you configured it but not quite.
> > You forgot to change the unix: in the zendframework.conf; which
> > it didn't matter since I didn't restart php-fpm and it kept
> > offering the socket at /run/php-fpm/php-fpm.sock
> 
> Sorry, it's possible I'm being completely dense here (no coffee yet) but I'm
> not sure what you mean? From comment #3 I have:
> 
> /etc/php-fpm.d/www.conf:
> listen = /run/php-fpm/php-fpm.sock
> 
> /etc/nginx/conf.d/zendframework.conf:
> fastcgi_pass unix:/run/php-fpm/php-fpm.sock

Yeah, ok. Forget about it; it is not relevant ;)

> > p.s. sorry for the delay but had to go to the hospital 'cause
> > my brother got some really painful kidney stones and had to be
> > operated.
> 
> No problem. Hope he's feeling better.
> 
> 
> Anyway, I've attached the set of configs I have. zendframework.conf uses the
> <domain> thingy and it seems to work on both nginx 1.2.5 and 1.2.7 when I
> access default.zf.local (gives me welcome to zf page) and somesite.zf.local
> (gives my phpinfo page). It would again be helpful if you could test those
> configs I've attached.

I did. They work fine. 

So, did you try changing from:
# /etc/nginx/conf.d/zendframework.conf
server {
    listen 80;
    server_name default.zf.local;
    root /srv/www/zendframework/default/public;
    index /index.php;
    location / {
        try_files $uri $uri/ /index.php;
    }
    location ~ \.php {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param APPLICATION_ENV development;
        include /etc/nginx/fastcgi_params;
    }
}


to:
# /etc/nginx/conf.d/zendframework.conf
server {
    listen 80;
    server_name ~^(?<domain>.+)\.zf\.local$;
    root /srv/www/zendframework/$domain/public;
    index /index.php;
    location / {
        try_files $uri $uri/ /index.php;
    }
    location ~ \.php {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param APPLICATION_ENV development;
        include /etc/nginx/fastcgi_params;
    }
}

And it works? That's odd... I don't know what is happening that, with me, it doesn't work on 1.2.5 and it does on 1.2.7

Well, if you can't replicate, it's a WORKSFORSOME I guess... ;=s

Comment 9 Jamie Nguyen 2013-03-08 10:08:52 UTC
I'll leave this open for now. Thanks for your input so far. Please do update this bug if you find out anything else about why the configuration attached does work but your configuration doesn't work.

Comment 10 Renich Bon Ciric 2013-03-08 10:39:21 UTC
I will look into this later; when I get some sleep, hehe. 4:39 am here. ;)

Comment 11 Renich Bon Ciric 2013-03-13 14:37:44 UTC
server {
    listen 80;
    server_name ~^(?<sub>.+?)\.(?<dom>.+)$;
    root /srv/www/html/$dom/$sub/public;
    index index.html index.htm;
    autoindex on;

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

    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
        # Some basic cache-control for static files to be sent to the browser
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }    

    location = /robots.txt { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }
    location ~ /\. { access_log off; log_not_found off; allow all; }
    location ~ ~$ { access_log off; log_not_found off; deny all; }
}

Please, try adding that, additionally, to your conf. This breaks the zend framework configuration.

This is the line that breaks things: 

    server_name ~^(?<sub>.+?)\.(?<dom>.+)$;

It seems that problems raise when you use two variables.

Comment 12 Jamie Nguyen 2013-03-15 10:27:32 UTC
Created attachment 710549 [details]
Working configuration

The configs attached works for me. They are identical the the previous configs I attached in comment #7 except two changes.

In /etc/nginx/conf.d/zendframework.conf:

    server_name ~^(?<subdomain>.+)\.(?<domain>.+)\.local$;
    root /srv/www/zendframework/$subdomain/$domain/public;

And in /etc/hosts:

    127.0.0.1    default.default.local
    127.0.0.1    somesite.default.local

Browsing to default.default.local gives me zend welcome page, and browsing to somesite.default.local gives me phpinfo. This is on both nginx 1.2.5 and 1.2.7.

Do these configs work for you? Two variables seems to work fine...

Comment 13 Jamie Nguyen 2013-03-26 13:54:14 UTC
Hi Renich, this bug needs more information and I can't reproduce the issues you've been having so I will close for now. Please re-open if required.