2016-11-14 12:13


I have a single page application, which written by AngularJS 1.5. I need SEO optimization this site. At first, i want make correct http response by server side. For example, it is adreess of non-existing article, the page must throw 404 error by server-side. How i can configure nginx server, for preprocessing all requests in php script? May be exists real recipe?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duan2477 duan2477 5年前

    Use the error_page directive so that when a 404 error occurs (when a requested file is not found), the custom page you created is served. We will create a location block for the file, where we are able to ensure that the root matches our file system location and that the file is only accessible through internal Nginx redirects (not requestable directly by clients):


             server {
                listen 80 default_server;
                listen [::]:80 default_server ipv6only=on;
                . . .
                error_page 404 /custom_404.html;
                location = /custom_404.html {
                        root /usr/share/nginx/html;

    Usually, we would not have to set the root in the new location block since it matches the root in the server block. However, we are being explicit here so that our error pages are served even if we move our regular web content and the associated document root to a different location.

    点赞 评论 复制链接分享