以下哪一个是与nginx的try_files指令等效的Apache指令

6ss1mwsb  于 2023-02-19  发布在  Apache
关注(0)|答案(1)|浏览(194)

请帮助,我是新的服务器配置。
我尝试在Apache的虚拟主机配置中编写下面的nginx服务器配置的等效配置。

server {

    root /path/to/public/root/directory;
    server_name myservername.test;

    location /api {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location /web {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location / {
        proxy_pass http://localhost:80;
    }

}

根据我的研究,我尝试做以下几点

<VirtualHost *:80>
        ServerName myservername.test
        DocumentRoot "/path/to/public/root/directory"

        <Directory /path/to/public/root/directory/>
                RewriteEngine on
                RewriteCond %{REQUEST_FILENAME} !-d  
                RewriteCond %{REQUEST_FILENAME} !-f

                RewriteCond %{REQUEST_FILENAME} "=/web" [OR]    
                RewriteCond %{REQUEST_FILENAME} "=/api"

                RewriteRule . index.php [QSA, L]
        </Directory>    
</VirtualHost>

<VirtualHost *:80>
        ServerName myservername.test
        ProxyPreserveHost On
        ProxyPass / http://localhost:8080/
        ProxyPassReverse / http://localhost:8080/
</VirtualHost>

但是它不起作用。我已经从上到下调整了代码,但是我的Apache服务器一直抛出错误。我的Apache版本是2. 4. 52
注意:我必须在apache的vhost而不是.htaccess文件中执行此操作
请帮忙,先谢了。

k7fdbhmy

k7fdbhmy1#

我终于让它工作了。
我犯的第一个错误是忘记启用mod_rewritemod_proxymod_proxy_http
第二个错误是我用相同的ServerName值创建了两个vhost,apache似乎忽略了其中一个
启用这些apache模块后,下面是对我有效的最终结果

<VirtualHost *:80>
    ServerName myservername.test
    #
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d  
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond "%{REQUEST_URI}" "=/web" [OR]    
    RewriteCond "%{REQUEST_URI}" "=/api"
    RewriteRule . index.php [QSA]
    #
    ProxyPass "/"  "http://localhost:80/"
    ProxyPassReverse "/"  "http://localhost:80/"
</VirtualHost>

相关问题