如何在 nginx 中配置别名

如何在 nginx 中配置别名

我正在从 apache 切换到 nginx,但我不确定如何在 nginx 中执行以下操作。

<VirtualHost *:80>
ServerName example.com
ProxyRequests On

Alias /faq /var/www/http
<Directory /var/www/http/>
    Options Indexes FollowSymLinks
    AllowOverride ALL
    Require all granted
</Directory>

ProxyPassMatch ^/faq !

ProxyPass        / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

ErrorLog ${APACHE_LOG_DIR}/http.log
CustomLog ${APACHE_LOG_DIR}/http.log combined

我目前有这个,但我一直收到 404 错误

server {
listen 80;
server_name example.com;
client_max_body_size 30M;

location / {
    proxy_pass  http://localhost:8080/;
    include /etc/nginx/proxy_params;
}

location /faq/ {
    proxy_redirect off;
    alias /var/www/http;
    index index.php;
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?q=$1 last;
    }

}

location ~ /faq\.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
#   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
#   # With php5-cgi alone:
#   fastcgi_pass 127.0.0.1:9000;
#   # With php5-fpm:
    fastcgi_pass unix:/var/run/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }

}

答案1

而不是alias /var/www/http;使用root /var/www/http;

另外,除了重定向到 index.php 之外,您还可以使用:

try_files $uri $uri/ /index.php?$args;

相关内容