Skip to content

php SERVER_PORT not configurable #231

@Jean-Daniel

Description

@Jean-Daniel

I'm trying to run wordpress behind unit following the documentation, but ran into an issue.

My wordpress site is distributed by NGINX using HTTPS, but Unit keep telling the PHP script that SERVER_PORT is 80. As Wordpress uses 'SERVER_PORT' to determine the actual URL scheme, it think the client tried to access the server using http instead of https, and send a 301 redirect to fix that.

As there is no way to specify SERVER variable in the configuration, I can't access my wordpress instance.

{
	"listeners": {
		"127.0.0.1:8090": {
			"pass": "applications/wp_index"
		},

		"127.0.0.1:8091": {
			"pass": "applications/wp_direct"
		}
	},

	"applications": {
		"wp_index": {
			"type": "php",
			"user": "www",
			"group": "www-data",
			"root": "/var/www/wordpress/",
			"script": "index.php"
		},

		"wp_direct": {
			"type": "php",
			"user": "www",
			"group": "www-data",
			"root": "/var/www/wordpress/",
			"index": "index.php"
		}
	}
}
server {
  listen 443 ssl http2 default_server;
  listen [::]:443 ssl http2 default_server;

  server_name wordpress.example.com;

  root /var/www/wordpress;

  ssl on;

  ssl_certificate /var/lib/acme/wordpress/rsa/cert.pem;
  ssl_certificate_key /var/lib/acme/wordpress/rsa/keys/key.pem;

  ssl_certificate /var/lib/acme/wordpress/ecdsa/cert.pem;
  ssl_certificate_key /var/lib/acme/wordpress/ecdsa/keys/key.pem;

  ssl_dhparam /var/lib/acme/wordpress/params.pem;

  # This order might seem weird - this is attempted to match last if rules below fail.
  # http://wiki.nginx.org/HttpCoreModule
  location / {
    try_files $uri @index_php;
  }

  location @index_php {
    proxy_pass http://unit_wp_index;
    proxy_set_header Host $host;
  }

  location /wp-admin {
    index index.php;
  }

  location ~* \.php$ {
    try_files        $uri =404;
    proxy_pass       http://unit_wp_direct;
    proxy_set_header Host $host;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🚀 Released

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions