[经过无数次尝试和几天的不懈搜索,我决定提出一个问题。我发现这是另一个问题的重复,这真让我感到惊讶,因为正如我说的那样,我真的尽我最大的努力来找出某人是否存在类似的问题。我在Google搜索的前两页都在purple letters now中:)
尽管有这些挫折,我相信这个问题可能并不是很难解决,只是我对角和apache的经验不足。
所以这是信息:
我有一个angular2应用程序,我想在服务器端进行渲染,以改善其SEO并改善在社交媒体上共享的网站链接的外观。
托管站点的服务器是Linux Ubuntu Linux ubuntu 18.04。
Web服务器应用程序是Apache2。
我已经按照官方Angular documentation的指示进行服务器端渲染。
另外,我启动了server.js文件,因此它在端口4000上为应用程序提供服务。我必须指出,在本地运行它没有问题。问题是当我尝试在服务器上运行它时...
出于安全原因,在本文中,我将不使用真实域。
打开页面时:www.mydomainexample.com/ssr,我收到此错误:
这是我的文件夹结构:
这里是apache2.conf
...
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
...
这里是.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ssr/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ - [L]
RewriteRule ^ /dist/browser/index.html
</IfModule>
<VirtualHost *:80>
ServerName mydomainexample.com
ServerAlias www.mydomainexample.com
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/
</VirtualHost>
<VirtualHost *:443>
ServerName mydomainexample.com
ServerAlias www.mydomainexample.com
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / https://localhost:4000/
ProxyPassReverse / https://localhost:4000/
</VirtualHost>
此外,我认为显示索引html文件的一部分很重要,并且我认为基本标记也很重要。这是index.html文件中的基本标记:
...
<base href="/">
...
如果我需要提供更多信息,请告诉我。
如果您的网站在/ssr
下运行,则需要使用<base href="/ssr">
来构建您的应用。
此外,您可能不需要dist
文件夹。 browser
和server
文件夹通常位于server.js旁边,但这可能取决于您的设置。