0

I'm looking for a config example to configure my CentOS server to run both PHP and Angular apps on the same domain. PHP Works fine so far and both apps will run under a regular user (non root) account.

My root PHP app is at public_html/

My Angular App is at public_html/app

Any help will be appreciated.

1
  • Excellent question. It's not super verbose like most others... beautiful and succinct and made it really easy to read as it applies exactly with what I was trying to do as well. Thank you! Commented Jul 8, 2020 at 15:17

1 Answer 1

2

People were hijacking this question and instead of providing answers they just posted complains about not providing sample code. I ended up finding the solution myself so I want to share it in case somebody is facing the same issues:

In my specific case I have both PHP and plain HTML (Angular) files serving in separate folders but under the same user/domain. The default config works correctly for PHP files but once I visited the folder /app where I have the Angular 8 app running I was getting a 502 error. To solve it I added the following to the default config file:

location /app/ {
    root /home/YOURUSER/public_html/app/;
    try_files $uri $uri/ /index.html /index.htm /index;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}
#Angular seems to have issues if you are not specific about CSS and JS files in headers
location ~ \.css {
    add_header Content-Type text/css;
}

location ~ \.js {
    add_header Content-Type application/x-javascript;
}

This seems to work correctly now.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this, not knowing nginx it was very difficult to figure this out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.