简体   繁体   English

.htaccess 文件转换为 nginx

[英].htaccess file convert to nginx

I have below .htaccess file and need to covert to nginx.Im having trouble with converting this.我有以下 .htaccess 文件,需要转换为 nginx。我在转换它时遇到了麻烦。 Im not nginx expert.我不是 nginx 专家。

RewriteEngine On
   
Options +FollowSymLinks
Options -Indexes

RewriteCond %{SCRIPT_FILENAME} !-d  
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L,QSA]
# Performace optimization  
# BEGIN Compress text files
<ifModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
  AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
  AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
  AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
  AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
  AddOutputFilterByType DEFLATE font/truetype font/opentype
</ifModule>
# END Compress text files

# BEGIN Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 5 seconds"
  ExpiresByType image/x-icon "access plus 31536000 seconds"
  ExpiresByType image/jpeg "access plus 31536000 seconds"
  ExpiresByType image/png "access plus 31536000 seconds"
  ExpiresByType image/gif "access plus 31536000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 31536000 seconds"
  ExpiresByType text/css "access plus 31536000 seconds"
  ExpiresByType text/javascript "access plus 31536000 seconds"
  ExpiresByType application/javascript "access plus 31536000 seconds"
  ExpiresByType application/x-javascript "access plus 31536000 seconds"
</ifModule>
# END Expire headers
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch ".(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "public"
  </filesMatch>
  <filesMatch ".(css)$">
    Header set Cache-Control "public"
  </filesMatch>
  <filesMatch ".(js)$">
    Header set Cache-Control "private"
  </filesMatch>
  <filesMatch ".(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
  </filesMatch>

  <filesMatch ".(woff|woff2|ttf|otf|eot)$">
    Header set Cache-Control "max-age=31536000 private, must-revalidate"
  </filesMatch>
</ifModule>

i tried a few online .htaccess converter but it didn't work can some one please let me know how to fix this?我尝试了一些在线 .htaccess 转换器,但它不起作用,有人可以告诉我如何解决这个问题吗?

Adjust the server block according to your hostname, protocol etc.根据您的主机名、协议等调整server块。

map $sent_http_content_type $expires {
    image/x-icon                   31536000;
    image/jpeg                     31536000;
    image/png                      31536000;
    image/gif                      31536000;
    application/x-shockwave-flash  31536000;
    text/css                       31536000;
    text/javascript                31536000;
    application/javascript         31536000;
    application/x-javascript       31536000;
    default                        5;
}

map $request_filename $cache_control {
    ~\.(ico|jpe?g|png|gif|swf)$    "public";
    ~\.css$                        "public";
    ~\.js$                         "private";
    ~\.(x?html?|php)$              "private, must-revalidate";
    ~\.(woff|woff2|ttf|otf|eot)$   "max-age=31536000 private, must-revalidate";
}

server {
    listen 80;
    server_name example.com;
    root /your/root/path;
    index index.php index.html index.htm;
    gzip on;
    gzip_types text/html text/xml text/css text/plain
               image/svg+xml application/xhtml+xml application/xml
               application/rdf+xml application/rss+xml application/atom+xml
               text/javascript application/javascript application/x-javascript application/json
               application/x-font-ttf application/x-font-otf
               font/truetype font/opentype;
    expires $expires;
    add_header Cache-Control $cache_control;
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    location ~ \.php$ {
        # your PHP handler here
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM