首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到具有Angular2 - 404的Apache

未找到具有Angular2 - 404的Apache
EN

Stack Overflow用户
提问于 2016-02-29 07:36:57
回答 3查看 3.7K关注 0票数 2

我已经使用Bitnami镜像在亚马逊网络服务服务器上部署了一个Angular2应用程序。这个应用程序由Apache提供服务(在端口8080上配置了一个虚拟主机),只要我从index.html启动,它就能正常工作。如果我想访问一个不同的页面(已经在RouteConfig中配置),我会得到一个404 not found错误。下面是虚拟服务器的配置:

代码语言:javascript
复制
Listen 8080
<VirtualHost _default_:8080>
  DocumentRoot "/opt/bitnami/apps/MyApp"
<Directory  "/opt/bitnami/apps/MyApp">
Options All
Require all granted
</Directory>
</VirtualHost>
EN

回答 3

Stack Overflow用户

发布于 2016-02-29 16:15:06

.htaccess文件添加到根文件夹。我使用的是:

代码语言:javascript
复制
# BEGIN ServeStatic

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

# END ServeStatic  

它为所有可能导致404...的请求提供index.html服务

票数 6
EN

Stack Overflow用户

发布于 2016-09-27 13:26:28

代码语言:javascript
复制
    ServerName angular2ssipl


    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/SSIPL-Angular

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    <Directory /var/www/html/SSIPL-Angular/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
            Require all granted

            RewriteEngine on
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [NC,L]
            RewriteRule ^(.*) /index.html [NC,L]
    </Directory>

票数 1
EN

Stack Overflow用户

发布于 2022-02-06 04:42:41

这就是我的工作(感谢@Ankur Loriya和其他许多人让我做到了这一点)……

转到包含index.html文件的目录。

代码语言:javascript
复制
sudo nano .htaccess

将以下内容添加到文件中:

代码语言:javascript
复制
RewriteEngine On
    # If an existing asset or directory is requested go to it as it is
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    RewriteRule ^ - [L]
    # If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

退出Nano (Control+X)并保存更改(Y)。

代码语言:javascript
复制
cd /etc/apache2
sudo nano apache2.conf

在文件的底部,有一系列<Directory>标记。找到下面这样写的:

代码语言:javascript
复制
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

...and将AllowOverride None更改为AllowOverride All

退出Nano (Control+X)并保存更改(Y)。

我不确定是否需要以下命令,但我做到了:

代码语言:javascript
复制
sudo a2enmod rewrite 

最后,重新启动Apache:

代码语言:javascript
复制
sudo service apache2 restart

这就完成了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35689696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档