nginx位置别名导致错误

我得到一个错误的nginx与我尝试sudo service nginx reload与以下包括:

 location /supermarkets.* { alias /supermarkets } 

我想要做的是,如果链接是例如111.111.11.11/supermarkets/something东西,它应该redirect到111.111.11.11/supermarkets 。 作为上下文,这是反应路由器,我想使用浏览器,而不是散列。

全部

 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: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # 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 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # 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; #} } 

使用nginx -t来testing您的configuration并识别语法错误。 您的location声明是不正确的语法,您的alias声明缺less终止; 。 详情请参阅此文件 。

您可能会混淆alias指令的function,请参阅此文档以获取详细信息。

你试图做的是通常使用try_files指令来实现。

例如:

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

以上将检查以/supermarkets开头的URI。 如果URI匹配本地文件,则返回,否则将返回/supermarkets/index.html

请参阅此文档了解更多

我注意到你的configuration也有一个location ~ \.php$ block,这意味着任何以/supermarkets开头,但以.php结尾的URI都不会被定向到/supermarkets/index.html