Nginx location alias causes error


I'm getting an error for nginx with I try to sudo service nginx reload with the following included:

location /supermarkets.* {
        alias /supermarkets

What I'm trying to do is if the link is e.g. it should redirect to As context, this is for react-router, I am trying to use browser rather than hash.

Full section

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #listen 443 ssl default_server;
    #listen [::]:443 ssl default_server;
    # Note: You should disable gzip for SSL traffic.
    # See:
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See:
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;

    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

    #   # With php7.0-cgi alone:
    #   fastcgi_pass;
    #   # With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

        location /supermarkets.* {
                alias /supermarkets

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #location ~ /\.ht {
    #   deny all;

Best Answer

Use nginx -t to test your configuration and identify syntax errors. Your location statement is incorrect syntax and your alias statement is missing a terminating ;. See this document for details.

You may be confusing the function of the alias directive, see this document for details.

What you are trying to do is usually achieved using a try_files directive.

For example:

location /supermarkets {
    try_files $uri /supermarkets/index.html;

The above will check URIs beginning with /supermarkets. If the URI matches a local file, it will be returned, otherwise /supermarkets/index.html will be returned.

See this document for more.

I notice that your configuration also has a location ~ \.php$ block which means that any URI beginning with /supermarkets, but ending with .php will not be directed to /supermarkets/index.html.