简体   繁体   中英

HTACCESS to NGINX

I'm trying to convert htaccess rules to nginx. I'm new to nginx and the online converter doesn't help either.

in www folder

<IfModule mod_rewrite.c>
    RewriteEngine on

   RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

inside public folder

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

could someone help me to convert these htaccess rules to nginx?

Maybe your config could look like this:

server {
  listen *:80;
  server_name source.example.com;
  server_tokens off; 

  location / {
        root /var/www;
  }

  location /public {
        root /var/www/public; # or so, put here your path to public dir
  }

  location @public {
    proxy_read_timeout 180;
    proxy_connect_timeout 180; 
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://host/public;
  }
}

I've forgotten some details but maybe you need something similar

if wordpress site is inside /var/www/html/web/wordpress then nginx config should be

location ~ ^/web/wordpress/index\.php$ { }

location /web/wordpress/ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
if (!-e $request_filename){
    rewrite ^/web/wordpress/(.*)$ /web/wordpress/index.php break;
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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