If you centre the rectangle on the origin, then it has vertices at $(-\frac{w}{2}, -\frac{h}{2})$, $(\frac{w}{2}, -\frac{h}{2})$, $(\frac{w}{2}, \frac{h}{2}),$ and $(-\frac{w}{2}, \frac{h}{2})$.
An ellipse centred at the origin has equation $\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1$ where $a$ is the 'horizontal' radius, and $b$ is the 'vertical' radius (here I am taking $a$, $b$ positive). Then the ellipse you are looking for must satisfy
$$a-\frac{w}{2} = b - \frac{h}{2}$$
or equivalently
$$2a - w = 2b - h.$$
If $w$ and $h$ are given, this is one equation between the two unknowns $a$ and $b$. This corresponds to the fact that there is an infinite family of ellipses which satisfies the distance condition.
You need one more piece of information to uniquely determine the ellipse. For example, if you would like the ellipse to go through the vertices of the rectangle, then we must have
$$\frac{\left(\dfrac{w}{2}\right)^2}{a^2} + \frac{\left(\dfrac{h}{2}\right)^2}{b^2} = \frac{w^2}{(2a)^2} + \frac{h^2}{(2b)^2} = 1.$$
Rearranging $b$ for $a$ in the previous equation, we obtain $b = a + \frac{1}{2}(h-w)$. Substituting into the latter equation, we see that $a$ must satisfy
$$\frac{w^2}{(2a)^2} + \frac{h^2}{(2a + h - w)^2} = 1$$
which, when rearranged, is a quartic in $a$.
Note, if $h = w$ (i.e. the rectangle is a square), then $a = b = \frac{w}{2}\sqrt{2}$ so the ellipse is a circle with radius equal to the distance between the origin and a vertex of the square (as one would expect).
Example: If $h = 1$ and $w = 2$ we obtain
$$\frac{4}{(2a)^2} + \frac{1}{(2a-1)^2} = 1$$
which becomes
$$4a^4-4a^3-4a^2+4a-1=0.$$
This only has two real roots, but the only positive one is $a = 1.2908$. From the first equation, we then see that $b = 0.7908$.
The result can be seen below (made using WolframAlpha).
Best Answer
One simple way of solving this problem is by Lagrange multipliers method. Note that if $(x,y)$ is in the first quadrant on the ellipse $x^2/a^2+y^2/b^2 = 1$, then the perimeter of the inscribed rectangle represented by $(x,y)$ is simply $4(x+y)$. Therefore you want to maximize $x+y$ given the constraint that $x^2/a^2+y^2/b^2 = 1$. Define $$ f(x,y,\lambda) = x+y -\lambda\left(\frac{x^2}{a^2}+\frac{y^2}{b^2}-1\right) $$ Hence by maximizing $f$ $$ 1 = \frac{2x\lambda}{a^2}=\frac{2y\lambda}{b^2}\Longrightarrow \frac{x}{a} = \frac{y}{b}\left(\frac{a}{b}\right) $$ but then $$1=\frac{x^2}{a^2}+\frac{y^2}{b^2}=\frac{y^2}{b^2}\left(1+\frac{a^2}{b^2}\right)\Longrightarrow y=\frac{b^2}{\sqrt{a^2+b^2}}, \quad x=\frac{a^2}{\sqrt{a^2+b^2}}$$ The maximum perimeter is therefore $4(x+y) = 4\sqrt{a^2+b^2}$.