[wp-trac] [WordPress Trac] #25239: $_SERVER['SERVER_NAME'] not a reliable when generating email host names

WordPress Trac noreply at wordpress.org
Fri Sep 6 14:17:50 UTC 2013


#25239: $_SERVER['SERVER_NAME'] not a reliable when generating email host names
-------------------------------------------------+-------------------------
 Reporter:  layotte                              |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Mail                                 |  Review
 Severity:  normal                               |     Version:  trunk
 Keywords:  has-patch dev-feedback needs-        |  Resolution:
  testing                                        |
-------------------------------------------------+-------------------------

Old description:

> For quite some time I have been having an issue with my comment
> notifications. The From address has been wordpress at _. I haven't paid much
> attention to this, but I had some spare time and decided to pursue the
> issue. Here it is...
>
> I am running WPMS w/ domains (latest stable) with Nginx and PHP5-FPM. In
> WordPress the comment notifications from email addresses are being
> generated using $_SERVER['SERVER_NAME'] to get the current site's domain
> name.
>
> e.g.
> {{{
> $wp_email = 'wordpress@' . preg_replace('#^www\.#', '',
> strtolower($_SERVER['SERVER_NAME']));
> }}}
>
> However, because of my environment my Nginx config for my site has the
> server_name set to "_" (underscore). Which is a catchall --
> http://nginx.org/en/docs/http/server_names.html.
>
> Site config in Nginx:
> {{{
> # Redirect everything to the main site.
> server {
>         listen [::]:80 default_server;
>         listen [::]:443 ssl;
>
>         ssl_certificate         /etc/nginx/ssl.crt/xxx.com.2012.crt;
>         ssl_certificate_key     /etc/nginx/ssl.key/xxx.com.2012.key;
>
>         server_name _;
>         root /var/www/xxx.com;
>         access_log /var/log/nginx/xxx.com.access.log;
>         error_log /var/log/nginx/xxx.com.error.log;
>         client_max_body_size 100m;
>
>         if ($http_host = "www.xxx.com") {
>                 rewrite ^ http://xxx.com$request_uri permanent;
>         }
>
>         include global/restrictions.conf;
>
>         # Additional rules go here.
>
>         include global/wordpress-ms.conf;
>
> }
> }}}
>
> The default fastcgi_params has this set:
> {{{
> fastcgi_param   SERVER_NAME             $server_name;
> }}}
>
> Thus, $_SERVER['SERVER_NAME'] is outputting "_" (underscore).
>
> I propose we move away from $_SERVER['SERVER_NAME'] when generating the
> from email addresses and use the available $current_site global object
> which stores the domain variable ($current_site->domain). I have
> implemented this change on my own site and have included the patch here.
>
> In the meantime, anyone else facing this problem can change their
> fastcgi_param to $host instead of $server_name. In my opinion, not the
> best solution, but it works for now.

New description:

 For quite some time I have been having an issue with my comment
 notifications. The From address has been wordpress at _. I haven't paid much
 attention to this, but I had some spare time and decided to pursue the
 issue. Here it is...

 I am running WPMS w/ domains (latest stable) with Nginx and PHP5-FPM. In
 WordPress the comment notifications from email addresses are being
 generated using `$_SERVER['SERVER_NAME']` to get the current site's domain
 name.

 e.g.
 {{{
 $wp_email = 'wordpress@' . preg_replace('#^www\.#', '',
 strtolower($_SERVER['SERVER_NAME']));
 }}}

 However, because of my environment my Nginx config for my site has the
 server_name set to "_" (underscore). Which is a catchall --
 http://nginx.org/en/docs/http/server_names.html.

 Site config in Nginx:
 {{{
 # Redirect everything to the main site.
 server {
         listen [::]:80 default_server;
         listen [::]:443 ssl;

         ssl_certificate         /etc/nginx/ssl.crt/xxx.com.2012.crt;
         ssl_certificate_key     /etc/nginx/ssl.key/xxx.com.2012.key;

         server_name _;
         root /var/www/xxx.com;
         access_log /var/log/nginx/xxx.com.access.log;
         error_log /var/log/nginx/xxx.com.error.log;
         client_max_body_size 100m;

         if ($http_host = "www.xxx.com") {
                 rewrite ^ http://xxx.com$request_uri permanent;
         }

         include global/restrictions.conf;

         # Additional rules go here.

         include global/wordpress-ms.conf;

 }
 }}}

 The default fastcgi_params has this set:
 {{{
 fastcgi_param   SERVER_NAME             $server_name;
 }}}

 Thus, `$_SERVER['SERVER_NAME']` is outputting "_" (underscore).

 I propose we move away from `$_SERVER['SERVER_NAME']` when generating the
 from email addresses and use the available $current_site global object
 which stores the domain variable ($current_site->domain). I have
 implemented this change on my own site and have included the patch here.

 In the meantime, anyone else facing this problem can change their
 fastcgi_param to $host instead of $server_name. In my opinion, not the
 best solution, but it works for now.

--

Comment (by SergeyBiryukov):

 Related: #16805

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


More information about the wp-trac mailing list