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
    • 最新
    • 标签
主页 / user-1007251

Axel's questions

Martin Hope
Axel
Asked: 2019-08-02 03:07:49 +0800 CST

Nginx 重写规则不起作用

  • 5

我们正在将网站从 Apache 迁移到 Nginx。到目前为止,我们从 .htaccess 规则转换为 nginx 的规则运行良好,但这个特定规则让我很难过。

我尝试过使用 if(我不使用)的在线转换器并手动尝试转换规则但没有任何效果。如果有人能指导我正确的方向或指出我出错的地方,那将有很大的帮助。

Apache .htaccess 规则:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-z]+)/([a-z]+).html$ /products/code_asset_2019.php?page=$1&filename=$2 [L]

RewriteRule ^(.*)/(.*\.php)$ /products/code.php?page=$1
RewriteRule ^(.*).html$ /products/code.php?page=$1

</IfModule>

目录结构: root /var/www/html;

里面

/html

,我们有/products包含code_asset_2019.php和code.php的文件夹

我转换后的规则不起作用:

location /products {
      try_files $uri $uri/ @rules;
    }

    location @rules {
    rewrite ^/([a-z]+)/([a-z]+)\.html$ /products/code_asset_2019.php?page=$1&filename=$2 last;
    rewrite ^/(.)/(.\.php)$ /products/code.php?page=$1;
    rewrite ^/(.*)\.html$ /products/code.php?page=$1;

    return 404;
}
apache-http-server php
  • 1 个回答
  • 960 Views
Martin Hope
Axel
Asked: 2019-04-25 01:33:34 +0800 CST

Wordpress 永久链接在 Nginx 中不起作用

  • 5

我正在将我的 wordpress 博客从 Apache 迁移到 Nginx。我已经尝试了多个教程来使永久链接正常工作,但对我来说没有任何效果。我的网站结构是这样的:

main site -> www.localhost.com

wordpress blog -> www.localhost.com/blog

网站在/var/www/html,wordpress安装在/var/www/html/blog

我阅读了多篇文章并观看了多个视频,但似乎没有任何效果。请让我知道我哪里出错了。

我定义了两个服务器块,/etc/nginx/sites-available/default 一个用于主站点,一个用于博客。

# Default server configuration
#
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.php index.html index.htm index.nginx-debian.html;

    server_name _;

       charset utf-8;
       error_page 404 /404.php;

       location /article {
         rewrite ^/article.* / redirect;
       }

       #location / {
        # try_files $uri $uri/ /loadpage.php?$args; 
       #}

       location ~ \.html$ {
         try_files $uri /courses/index.php?$args;
       }





    # 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:/var/run/php/php7.0-fpm.sock;
                include fastcgi_params;

    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}



server {
    listen 80;
    listen [::]:80;
    root /var/www/html/blog;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;

    location /blog/ {
    try_files $uri $uri/ /blog/index.php?$args;        
    }


    location ~ \.php$ {
    fastcgi_split_path_info  ^(.+\.php)(/.+)$;
    fastcgi_index            index.php;
 #  fastcgi_pass             unix:/var/run/php/php7.1-fpm.sock; #Ubuntu 17.10
    fastcgi_pass             unix:/var/run/php/php7.0-fpm.sock; #Ubuntu 17.04
    include                  fastcgi_params;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}
nginx apache-http-server
  • 1 个回答
  • 453 Views
Martin Hope
Axel
Asked: 2019-04-24 02:55:37 +0800 CST

Apache 到 Nginx mod_rewrite 规则

  • 5

我为 nginx 转换了一些 mod_rewrite 规则,当我在本地测试时它们工作正常,但由于某种原因它们在我的网站上不起作用。

任何人都可以帮助我出错的地方吗?

阿帕奇规则:

<filesMatch "\.(htm|html|css|js|php)$">

AddDefaultCharset UTF-8

DefaultLanguage en-US

</filesMatch>
<IfModule mod_rewrite.c>
ErrorDocument 404 /404.php
RewriteEngine On
RewriteRule ^article.*$ / [R=301,L]



RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*\.* /loadpage.php [QSA,L]

</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*\.html /courses/index.php [L]

</IfModule>

Nginx 转换规则:

 charset utf-8;
        error_page 404 /404.php;
location /article {
         rewrite ^/article.*$ / redirect;
        }

        location / {
         if (!-e $request_filename){
          rewrite ^/.*\.* /loadpage.php break;
          }
         }

          if (!-e $request_filename){
           rewrite ^/.*\.html /courses/index.php break;
          }
nginx apache-http-server
  • 1 个回答
  • 285 Views

Sidebar

Stats

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

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve