【问题标题】:Rewrite .htaccess to Nginx configuration format to proxy different URLs to different ports [closed]将 .htaccess 重写为 Nginx 配置格式以将不同的 URL 代理到不同的端口 [关闭]
【发布时间】:2021-07-25 05:45:42
【问题描述】:

如何在 nginx 中使用以下 htaccess 规则?

所以如果用户访问http://lovelythings.buzz/apiimg 应该使用本地端口8080。

但是当尝试访问其他路由http://lovelythings.buzz时,它会被代理到端口3000或3001

这我已经在 .htaccess 上为 Apache2 服务器实现了。

但是在其他服务器上我安装了 Nginx 并且 Nginx 不支持.htaccess

下面是.htaccess,我正在尝试在Nginx上运行。

DirectoryIndex
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} dev.farrwest.com
RewriteRule  ^api(.*)$  http://localhost:8080/api$1 [P,L]
RewriteRule  ^img/(.*)$  http://localhost:8080/img/$1 [P,L]
RewriteRule ^(.*)?$ http://localhost:3001/$1 [P,L]

【问题讨论】:

    标签: .htaccess nginx vue-storefront


    【解决方案1】:

    经过进一步的搜索。

    以下配置对我来说工作正常。

    server {
        listen 80;
        listen [::]:80;
    
        server_name lovelythings.buzz www.lovelythings.buzz;
    
        #root /var/www/html;
        index index.html index.htm index.nginx-debian.html; 
    
        location / {
            proxy_pass http://localhost:3000/;
        }
    
        location /assets/ {
            proxy_pass http://localhost:3000/assets/;
        }
    
        location /api/ {
            proxy_pass http://localhost:8080/api/;
        }
    
        location /graphql {
            proxy_pass http://localhost:8080/graphql;
        }
      
        location /img/ {
            proxy_pass http://localhost:8080/img/;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-11-04
      • 1970-01-01
      • 2021-05-29
      • 2021-03-18
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 2013-03-18
      • 2017-06-29
      相关资源
      最近更新 更多