Score:0

Nginx rewrite rule to make php see https scheme

cn flag

I want my pho application to only see the https scheme even if the secure connection is already terminated.

I have the following setup: Browser --https--> nginx --http--> nginx --> php-fpm socket

Now I need the php application to only note about the original https scheme request.

Is that even possible?

The only alternative I see is to make the nginx to nginx traffic also over https. But I want to avoid the overhead for local traffic.

Tarion avatar
cn flag
Another way would be to hope that the application handles x-forwarded-proto headers. I will check that as well.
Richard Smith avatar
jp flag
The PHP application will probably use either `$_SERVER['REQUEST_SCHEME']` or `$_SERVER['HTTP_X_FORWARDED_PROTO']` to determine the scheme. These parameters can be set and/or overridden in your Nginx configuration file.
Tarion avatar
cn flag
HTTP_X_FORWARDED_PROTO ist just the head field. How to override the REQUEST_SCHEME?
Tarion avatar
cn flag
Maybe this is what I need? https://www.nginx.com/resources/wiki/start/topics/examples/fastcgiexample/
Score:0
cn flag

The solution is to override the properties using fastcgi_param REQUEST_SCHEME 'https'; after include fastcgi.conf;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    #   # With php5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_param   REQUEST_SCHEME  'https';
    fastcgi_param   HTTPS           'on';
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.