A nice approach to derive this is to work in four-vector formalism from the start as Eigenchris does. Now, we want, by the orthogonality of time and space coordinates that
$$\hat{e}_x\cdot\hat{e}_t=\hat{e}_t\cdot\hat{e}_x=0$$
and by definition of metric $\hat{e}_x\cdot\hat{e}_x=g_{xx},\hat{e}_t\cdot\hat{e}_t=g_{tt}, \hat{e}_x\cdot\hat{e}_t=g_{xt}=g_{tx}$.
We also want
$$\hat{e}_{x'}\cdot\hat{e}_{t'}=\hat{e}_{t'}\cdot\hat{e}_{x'}=0$$
Where prime refers to some other inertial coordinate with axes parallel to (ct,x) coordinates.
The bases vector transformation, which can be derived from Lorentz transformations gives:
$$\hat{e}_{x'}=\gamma(\hat{e}_{x}+\beta\hat{e}_{t})$$
$$\hat{e}_{t'}=\gamma(\hat{e}_{t}+\beta\hat{e}_{x})$$
Thus demanding $\hat{e}_{t'}\cdot\hat{e}_{x'}=0$ gives
$$\gamma^2((\hat{e}_{x}+\beta\hat{e}_{t}))\cdot(\hat{e}_{t}+\beta\hat{e}_{x})=0$$
$$-\hat{e}_{x}\cdot\hat{e}_{x}=\hat{e}_{t}\cdot\hat{e}_{t}=\varphi=g_{tt}$$
Therefore our metric becomes
$$\varphi\begin{pmatrix}1 & 0\\\ 0 & -1 \end{pmatrix}$$
Here we set $\varphi=1$ (or $-1$) for simplicity.