[wp-trac] [WordPress Trac] #18852: Nginx rewrite rules

WordPress Trac noreply at wordpress.org
Wed Nov 13 03:58:38 UTC 2013


#18852: Nginx rewrite rules
-------------------------------------+--------------------------
 Reporter:  johnbillion              |       Owner:  johnbillion
     Type:  enhancement              |      Status:  accepted
 Priority:  normal                   |   Milestone:  3.8
Component:  Rewrite Rules            |     Version:  3.3
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |
-------------------------------------+--------------------------

Comment (by rmccue):

 I'd like to start working on this again, since I think we can make some
 traction here.

 Replying to [comment:26 jeremyfelt]:
 > The `nginx-wp-common.conf` that we've [https://github.com/10up/varying-
 vagrant-vagrants/blob/master/config/nginx-config/nginx-wp-common.conf
 pieced together in VVV] has served pretty well thus far, though I'm sure
 there's plenty of room for improvement. Ignoring the Vagrant/VM specific
 directives like `gzip off;`, it may be a good starting point for
 discussion and I'm willing to make tweaks to that default config as needed
 if it can provide a good testing ground for core.

 I think this is a great start, and matches the standard config I use too.

 Going over individual bits of the config:

 {{{
 try_files $uri $uri/ /index.php?$args;
 }}}

 That should be `/index.php$is_args$args` instead (`$is_args = "?"` if
 `$args` is non-empty, or `""` otherwise), per best practices.

 {{{
 # Add trailing slash to */wp-admin requests.
 rewrite /wp-admin$ $scheme://$host$uri/ permanent;
 }}}

 Do we need this? :)

 {{{
 # Pass uploaded files to wp-includes/ms-files.php.
 rewrite /files/$ /index.php last;

 if ($uri !~ wp-content/plugins) {
     rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
 }

 # Rewrite multisite in a subdirectory '.../wp-.*' and '.../*.php'.
 if (!-e $request_filename) {
     rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
     rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
     rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
 }
 }}}

 I'd separate this into an `nginx-wp-multisite.conf` personally.

 {{{
     # The amount of time for upstream to wait for a fastcgi process to
 send data.
     # We keep this *extremely* high so that one can be lazy when remote
 debugging.
         fastcgi_read_timeout 3600s;

     # Buffer size for reading the header of the backend FastCGI process.
     # This defaults to the value of a single fastcgi_buffers, so does not
     # need to be specified in our case, but it's good to be explicit.
         fastcgi_buffer_size 128k;

     # The number and size of the buffers into which the reply from the
 FastCGI
     # process in the backend is read.
     #
     # 4 buffers at 128k means that any reply by FastCGI greater than 512k
 goes
     # to disk and replies under 512k are handled directly in memory.
     fastcgi_buffers 4 128k;
 }}}

 I think we should avoid duplicating `fastcgi_params` content where
 possible, and this stuff should definitely live there. (Also, interesting
 note, you've got mixed spaces and tabs in the file :) )

 {{{
 fastcgi_pass   php;
 }}}

 (I'm not sure how we can *not* hardcode this, so this is probably a good
 idea. Anyone using other FPM setups can obviously roll their own config.)

--
Ticket URL: <http://core.trac.wordpress.org/ticket/18852#comment:32>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list