AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[ngx-http-rewrite-module](server)

Martin Hope
zigojacko
Asked: 2022-03-30 22:55:33 +0800 CST

停止 Nginx 重写破坏位置块之后的所有页面

  • 1

我不得不重写 nginx.conf 中包含特定查询参数的 URL;

举个例子:-

location /brands/exampleA {

    if ($arg_cat = "9") {
        return 301 /page/brand-filter;
    }

    if ($arg_cat = "38") {
        return 301 /page/category/brand-filter;
    }

}

然后,这些 URL 重写将重写example.com/brands/exampleA/?cat=9为example.com/page/brand-filter和。example.com/brands/exampleA/?cat=38example.com/page/category/brand-filter

这些工作完美,但问题是它们破坏了位置块的所有其他子页面,例如,以下页面都不会加载 Nginx 错误:-

example.com/brands/exampleA/range1
example.com/brands/exampleA/range2
example.com/brands/exampleA/range3
example.com/brands/exampleA/range4

那么有什么我可以添加到 location 语句中以停止任何应用于之后的任何内容exampleA- 这些重写应该只匹配 ?cat= 查询参数。

nginx ngx-http-rewrite-module
  • 1 个回答
  • 63 Views
Martin Hope
NoobAvi
Asked: 2021-07-11 08:09:21 +0800 CST

Apache .htaccess 到 NGINX RewriteRules 端口

  • 2

所以,我实际上正在尝试将RewriteRules 从Apache移植到NGINX,但似乎我无法完全移植。

实际上,在我的服务器上,我确实在服务器上的https://example.com域和/var/www/html/路径上有一个正在运行的站点。我要做的是在var/www/html/subdirectorypath 和 domain下的子目录中安装自定义脚本https://example.com/subdirectory。

问题是重写规则不起作用,甚至出现 404 not found 错误。请帮助我。

我的 Apache.htaccess文件:

RewriteRule ^page/?$ pages/page.php [L]
RewriteRule ^about/?$ pages/about.php [L]
RewriteRule ^privacy-policy/?$ pages/privacy-policy.php [L]
RewriteRule ^contact/?$ pages/contact.php [L]
RewriteRule ^terms/?$ pages/tos.php [L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) - [PT,L]

RewriteRule ^sitemap-([0-9]+).xml$ parts/sitemaps/sitemap-$1.xml [QSA,L]

RewriteRule ^(.*)/(.*)/(.*)/(.*)/?$ index.php?bank=$1&state=$2&district=$3&branch=$4 [QSA,L]
RewriteRule ^(.*)/(.*)/(.*)/?$ index.php?bank=$1&state=$2&district=$3 [QSA,L]
RewriteRule ^(.*)/(.*)/?$ index.php?bank=$1&state=$2 [QSA,L]
RewriteRule ^(.*)/?$ index.php?bank=$1 [QSA,L]

和NGINX config我试图移植的文件:

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

  root /var/www/html;

  # Add index.php to the list if you are using PHP
  index index.php index.html;

  server_name localhost;

  location /
  {
    try_files $uri $uri/ =404;
  }

  # pass PHP scripts to FastCGI server
  location ~ \.php$
  {
    include snippets/fastcgi-php.conf;
    #       # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
  }

  location /subdirectory
  {

    root /var/www/html/subdirectory;
    index index.php;
    try_files $uri $uri/ /index.php$args$query_string

    location ~ ^/(.+)
    {
    }

    location /page
    {
      rewrite ^/page/?$ /pages/page.php break;
    }

    location /about
    {
      rewrite ^/about/?$ /pages/about.php break;
    }

    location /privacy
    {
      rewrite ^/privacy-policy/?$ /pages/privacy-policy.php break;
    }

    location /contact
    {
      rewrite ^/contact/?$ /pages/contact.php break;
    }

    location /terms
    {
      rewrite ^/terms/?$ /pages/tos.php break;
    }

    location /
    {
      if (-e $request_filename)
      {
        rewrite ^/sitemap-([0-9]+).xml$ /parts/sitemaps/sitemap-$1.xml break;
      }
      rewrite ^/(.*)/(.*)/(.*)/(.*)/?$ /index.php?bank=$1&state=$2&district=$3&branch=$4 break;
      rewrite ^/(.*)/(.*)/(.*)/?$ /index.php?bank=$1&state=$2&district=$3 break;
      rewrite ^/(.*)/(.*)/?$ /index.php?bank=$1&state=$2 break;
      rewrite ^/(.*)/?$ /index.php?bank=$1 break;
    }

    location ~ /subdirectory /(.+\.php)$
    {
      include snippets/fastcgi-php.conf;
      # With php-fpm (or other unix sockets):
      fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
      # With php-cgi (or other tcp sockets):
      # fastcgi_pass 127.0.0.1:9000;
    }

  }
}
rewrite nginx ngx-http-rewrite-module
  • 1 个回答
  • 156 Views
Martin Hope
LK86
Asked: 2021-03-02 09:21:28 +0800 CST

重写uri以删除nginx中的www

  • 1

我有未知数量的域与www.abc123.example.com. “abc”后面的数字是未知的。我想也许我可以使用正则表达式的重写规则~*(www\.abc\w+)

就像是:

server_name ~*(www\.abc\w+)
rewrite ~*(www\.abc\w+)\.example\.com (abc\w+)\.example\.com;

不幸的是,这似乎不起作用,并且 uri 没有改变。我的其他想法可能是尝试设置/重写 $uri 值,但我也没有成功。

我不确定我是否未能匹配 uri 值或未能重写 uri(或两者兼而有之)。

我能够做到这一点:

if ($host ~* ^www\.(.*)) {       
set $host_without_www $1;
rewrite ^(.*) http://$host_without_www$1 permanent;
}

不幸的是,这会重写所有“www”流量,而不仅仅是 www.abc123。任何帮助表示赞赏。谢谢你。

ubuntu nginx ngx-http-rewrite-module
  • 1 个回答
  • 117 Views
Martin Hope
SBotirov
Asked: 2020-11-04 23:35:48 +0800 CST

NGINX 1.13.8 重写 url 不起作用

  • 1

我有以下重写位置:

location ~ ^/payment/gateway/v2/order/complete/(.*)$ {
    proxy_pass http://api.test.com:8080/payment/gateway/v2/order/complete?order_id=$1;
}

然后我尝试了这个:

 location /payment/gateway/v2/order/complete {
    rewrite ^/payment/gateway/v2/order/complete/(.+) /payment/gateway/v2/order/complete?order_id=$1 break;
    proxy_pass http://api.test.com:8080
}

那么这个:

 location /payment/gateway/v2/order/complete/ {
    rewrite ^/payment/gateway/v2/order/complete/$ /payment/gateway/v2/order/complete?order_id=$1 last;
    proxy_pass http://api.test.com:8080
}

那么这个:

location /payment/gateway/v2/order/complete {
    rewrite ^/payment/gateway/v2/order/complete/([^/]+)$ /payment/gateway/v2/order/complete?order_id=$1 last;
    proxy_pass http://api.test.com:8080;
}

所有这些都不起作用。

编辑:这是完整的 nginx 配置:

server {
    listen  443 ssl;
    server_name api.test.com www.api.test.com;

    ssl_certificate /home/ssl/api.test.com/cert.pem;
    ssl_certificate_key /home/ssl/api.test.com/key.pem;
    ssl_protocols SSLv3 TLSv1.2;
    ssl_ciphers  "RC4:HIGH:!aNULL:!MD5:!kEDH";
    add_header Strict-Transport-Security 'max-age=604800';

    access_log /var/log/nginx/api.test.access.log;
    error_log /var/log/nginx/api.test.error.log;

    root  /home/test;

    include /etc/nginx/conf/wellknown.conf;

    location /payment/paypal {
        proxy_pass http://api.test.com:8080;
    }

    location /payment/visa {
        proxy_pass http://api.test.com:8080;
    }

    location /payment/gateway {
        proxy_pass http://api.test.com:8080;
    }
    
    location /payment/gateway/order/complete {
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        proxy_pass http://api.test.com:8080;
    }

    location /payment/gateway/v2/order/complete {
        rewrite ^/payment/gateway/v2/order/complete/(.+) /payment/gateway/v2/order/complete?order_id=$1 break;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_pass http://api.test.com:8080;
    }

    location /payment/mastercard/order {
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        proxy_pass http://api.test.com:8080;
    }

    location /payment/mir/order {
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        proxy_pass http://api.test.com:8080;
    }

    location /payment/v1 {
        proxy_pass http://api.test.com:8080;
    }
    
    location /catalog {
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
        proxy_pass http://localhost:9202;   
     }

    location / {
         if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Locale';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
         }
         if ($request_method = 'POST') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
         }
         if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
         }
    }

    location /test-rpc {
        proxy_pass http://api.test.com:8080;
    }
}

EDIT2:这里 wellknown.conf 配置文件正文:

location ^~ /.well-known/ {
    default_type "text/plain";
    allow all;
}

EDIT3我优化了位置,但不影响最终结果:

server {
    listen  443 ssl;
    server_name api.test.com www.api.test.com;

    ssl_certificate /home/ssl/api.test.com/cert.pem;
    ssl_certificate_key /home/ssl/api.test.com/key.pem;
    ssl_protocols SSLv3 TLSv1.2;
    ssl_ciphers  "RC4:HIGH:!aNULL:!MD5:!kEDH";
    add_header Strict-Transport-Security 'max-age=604800';

    access_log /var/log/nginx/api.test.access.log;
    error_log /var/log/nginx/api.test.error.log;

    root  /home/test;

    include /etc/nginx/conf/wellknown.conf;
    
    location /payment/gateway/v2/order/complete {
        rewrite ^/payment/gateway/v2/order/complete/(.+) /payment/gateway/v2/order/complete?order_id=$1 break;
        proxy_pass http://api.test.com:8085;
    }  

    location /payment {
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_pass http://api.test.com:8085;
    }

    location /catalog {
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_pass http://localhost:9202;
    }

    location / {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Locale';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;

            return 204;
        }

        if ($request_method = 'POST') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        }

        if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
            add_header 'Access-Control-Expose-Headers' 'Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        }
    }

    location /test-rpc {
        proxy_pass http://api.test.com:8080;
    }
}

Nginx 版本 1.13.8

提前致谢

nginx ngx-http-rewrite-module
  • 2 个回答
  • 394 Views
Martin Hope
Oliver Weichhold
Asked: 2020-10-23 06:38:00 +0800 CST

将图像请求重写到 Nginx 中的子目录结构

  • 0

给定这样的位置:

location ~ ^/user-content/img/) {
  root /srv/foo/bar/uploads/;
  autoindex off;
  access_log off;
  expires 30d;
}

是否可以使用 nginx 请求

/user-content/img/3AF1D3A69CE92ADAED8B0D25C2411595C7C798A5.png

要从目录中实际提供服务,/srv/foo/bar/uploads/3A/F1/D3这将涉及从请求文件名中获取前两个字符并将它们用作第一个子文件夹,然后将字符 3-4 用于下一个更深的文件夹,最后为最后一个子文件夹附加字符 5-6?

rewrite nginx ngx-http-rewrite-module
  • 2 个回答
  • 357 Views
Martin Hope
Elin Digente
Asked: 2020-07-25 14:03:13 +0800 CST

将 htaccess 转换为 Nginx ReWrite(自动转换不起作用)

  • 1

嗨,有人碰巧知道 Nginx 重写规则吗?

我正在尝试将此 Apache .htaccess 转换为 Nginx Rewrite,我已经尝试过使用在线转换器

登录后主页和仪表板工作正常,但:新闻、列表、视频、音乐、民意调查和测验部分无法正常工作,他们给出 404

我有 32 小时不间断不睡觉设置服务器它让我发疯

任何帮助将不胜感激

这是我要转换的 Apache .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^$ index.php?link1=home [NC,QSA]
RewriteRule ^news/(.*)$ index.php?link1=news&id=$1 [NC,QSA]
RewriteRule ^lists/(.*)$ index.php?link1=lists&id=$1 [NC,QSA]
RewriteRule ^polls/(.*)$ index.php?link1=polls&id=$1 [NC,QSA]
RewriteRule ^quiz/(.*)$ index.php?link1=quiz&id=$1 [NC,QSA]
RewriteRule ^videos/(.*)$ index.php?link1=videos&id=$1 [NC,QSA]
RewriteRule ^music/(.*)$ index.php?link1=music&id=$1 [NC,QSA]
RewriteRule ^edit-post/(.*)$ index.php?link1=edit-post&id=$1 [NC,QSA]
RewriteRule ^delete-post/(.*)$ index.php?link1=delete-post&id=$1 [NC,QSA]
RewriteRule ^settings/(.*)/(.*)$ index.php?link1=settings&page=$1&user=$2 [NC,QSA]
RewriteRule ^settings/(.*)$ index.php?link1=settings&page=$1 [NC,QSA]
RewriteRule ^admin-cp$ admincp.php [NC,QSA]
RewriteRule ^admin-cp/(.*)$ admincp.php?page=$1 [NC,QSA]
RewriteRule ^admincp/(.*)$ index.php?link1=admincp&page=$1 [NC,QSA]
RewriteRule ^admin-cdn/(.*)$ admin-panel/$1 [L]
RewriteRule ^tags/(.*)$ index.php?link1=tags&tag=$1 [NC,QSA]
RewriteRule ^feeds/rss(/?|)$ index.php?link1=feeds&page=home [NC,QSA]
RewriteRule ^post_data/(.*)/(.*)(/?|)$ index.php?link1=post_data&post_type=$1&id=$2 [NC,QSA]

RewriteRule ^terms/(.*)$ index.php?link1=terms&type=$1 [NC,QSA]
RewriteRule ^go_pro(?:\/{0,1}|)$ index.php?link1=go_pro [NC,QSA]

RewriteRule ^latest-(.*)/(\d+)$ index.php?link1=latest-$1&c_id=$2 [NC,QSA]
RewriteRule ^latest-(.*)/rss(/?|)$ index.php?link1=rss&page=$1 [NC,QSA]

RewriteRule ^ads(?:\/?|)$ index.php?link1=ads [NC,QSA]
RewriteRule ^ads/create-new(?:\/?|)$ index.php?link1=create_ad [NC,QSA]
RewriteRule ^ads/edit/([0-9]+)(?:\/?|)$ index.php?link1=edit_ad&ad_id=$1 [NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^@([^\/]+)(\/|)$ index.php?link1=profile&u=$1 [QSA]
RewriteRule ^@([^\/]+)(\/|)/(.*)$ index.php?link1=profile&u=$1&page=$2 [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\/]+)(\/|)$ index.php?link1=$1 [QSA]

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

这是自动转换的文件(部分工作,在我的一些版本之后,基于 3 小时阅读 Nginx 文档)

location / {
  if (!-e $request_filename){
    rewrite ^/$ /index.php?link1=home;
  }
  rewrite "^/go_pro(?:\/{0,1}|)$" /index.php?link1=go_pro;
  if (!-e $request_filename){
    rewrite ^/@([^\/]+)(\/|)$ /index.php?link1=profile&u=$1;
  }
  rewrite ^/@([^\/]+)(\/|)/(.*)$ /index.php?link1=profile&u=$1&page=$2;
  if (!-e $request_filename){
    rewrite ^/([^\/]+)(\/|)$ /index.php?link1=$1;
  }
}


(**_not working from here and below news, list, video, music, polls and quiz sections_**)

location /news {
  rewrite ^/news/(.*)$ /index.php?link1=news&id=$1;
}

location /lists {
  rewrite ^/lists/(.*)$ /index.php?link1=lists&id=$1;
}

location /polls {
  rewrite ^/polls/(.*)$ /index.php?link1=polls&id=$1;
}

location /quiz {
  rewrite ^/quiz/(.*)$ /index.php?link1=quiz&id=$1;
}

location /videos {
  rewrite ^/videos/(.*)$ /index.php?link1=videos&id=$1;
}

location /music {
  rewrite ^/music/(.*)$ /index.php?link1=music&id=$1;
}

location /edit {
  rewrite ^/edit-post/(.*)$ /index.php?link1=edit-post&id=$1;
}

location /delete {
  rewrite ^/delete-post/(.*)$ /index.php?link1=delete-post&id=$1;
}

location /settings {
  rewrite ^/settings/(.*)/(.*)$ /index.php?link1=settings&page=$1&user=$2;
  rewrite ^/settings/(.*)$ /index.php?link1=settings&page=$1;
}

(**_admin panel and the other admin, term, ads, latest,tags and feed and all rest sections below this line work fine_**)

location /admin {
  rewrite ^/admin-cp$ /admincp.php;
  rewrite ^/admin-cp/(.*)$ /admincp.php?page=$1;
}

location /admincp {
  rewrite ^/admincp/(.*)$ /index.php?link1=admincp&page=$1;
}

location /admin-cdn/ {
  alias /admin-panel/;
}

location /tags {
  rewrite ^/tags/(.*)$ /index.php?link1=tags&tag=$1;
}

location /feeds {
  rewrite ^/feeds/rss(/?|)$ /index.php?link1=feeds&page=home;
}

location /post_data {
  rewrite ^/post_data/(.*)/(.*)(/?|)$ /index.php?link1=post_data&post_type=$1&id=$2;
}

location /terms {
  rewrite ^/terms/(.*)$ /index.php?link1=terms&type=$1;
}

location /latest {
  rewrite ^/latest-(.*)/(\d+)$ /index.php?link1=latest-$1&c_id=$2;
  rewrite ^/latest-(.*)/rss(/?|)$ /index.php?link1=rss&page=$1;
}

location /ads {
  rewrite ^/ads(?:\/?|)$ /index.php?link1=ads;
  rewrite ^/ads/create-new(?:\/?|)$ /index.php?link1=create_ad;
  rewrite ^/ads/edit/([0-9]+)(?:\/?|)$ /index.php?link1=edit_ad&ad_id=$1;
}

如果我在问题中犯了任何错误;请原谅我几乎没有醒来,我是一名电子工程师,正在尝试为我的物联网设备设置服务器前端和后端;我不是程序员,但我非常钦佩他们,学习了一些基本的 WebDeV,但这是我第一次使用 Nginx 编码不是我的强项,并不是每个人都对我很好https://stackoverflow.com/questions/63078446/converting -htaccess-to-nginx-rewrite-autoconverting-not-working?noredirect=1#comment111550833_63078446

任何帮助将不胜感激提前谢谢

rewrite .htaccess web nginx ngx-http-rewrite-module
  • 1 个回答
  • 299 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve