You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Plesk环境下Angular 8部署问题:仅首页正常其余页面404 Not Found

Fixing 404 Errors on Non-Home Pages for Angular 8 Apps in Plesk

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)

  1. Log into your Plesk panel and navigate to the domain’s Apache & Nginx Settings.
  2. Scroll down to the sections labeled Additional directives for HTTP and Additional directives for HTTPS.
  3. 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>
  1. 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):

  1. Go to the domain’s Apache & Nginx Settings.
  2. Find the Additional nginx directives field.
  3. Add this rule:
location / {
  try_files $uri $uri/ /index.html;
}
  1. 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 --prod locally, then upload the contents of the dist folder to your Plesk website’s root directory (not the dist folder itself).
  • Double-check that Plesk’s Document Root for the domain is pointing to the folder where index.html lives (usually httpdocs if you uploaded directly there).
  • Clear your browser cache—sometimes old routing data can cause unexpected issues.

内容的提问来源于stack exchange,提问作者Murugan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 14:44:08