Plesk环境下Angular 8部署问题:仅首页正常其余页面404 Not Found
Hey there, I’ve dealt with this exact headache when deploying Angular apps on Plesk—let’s get your routes working properly!
Why This Happens
Angular is a single-page application (SPA), which means all routing happens in the browser, not on the server. When you try to access https://abcd.xyz/login directly (or refresh that page), the server looks for a physical file at /login—which doesn’t exist, hence the 404. We need to tell the server to send all non-static requests to index.html so Angular can handle the routing.
Fix for Apache (Most Common in Plesk)
- Log into your Plesk panel and navigate to the domain’s Apache & Nginx Settings.
- Scroll down to the sections labeled Additional directives for HTTP and Additional directives for HTTPS.
- Paste this rewrite rule into both boxes (or just the HTTPS one if you’re only using SSL):
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>
- Save the settings and test your routes again.
Alternatively, if your Plesk setup allows .htaccess files, you can create one in your website’s root directory (usually httpdocs) with the same code above.
Fix for Nginx
If your Plesk server uses Nginx (either standalone or alongside Apache):
- Go to the domain’s Apache & Nginx Settings.
- Find the Additional nginx directives field.
- Add this rule:
location / { try_files $uri $uri/ /index.html; }
- Save and test—your
/login(and other) routes should now load correctly.
Quick Checks to Ensure Success
- Make sure you built your Angular app for production: run
ng build --prodlocally, then upload the contents of thedistfolder to your Plesk website’s root directory (not thedistfolder itself). - Double-check that Plesk’s Document Root for the domain is pointing to the folder where
index.htmllives (usuallyhttpdocsif you uploaded directly there). - Clear your browser cache—sometimes old routing data can cause unexpected issues.
内容的提问来源于stack exchange,提问作者Murugan

