Jump to content

Rewrite no NGINX


ricardolucas

Recommended Posts

Olá pessoal, tudo bem ?

Estou migrando um site para outro servidor, agora com Nginx+PHP-FPM+MariaDB. Entre trancos e barrancos consegui colocar pra rodar.

O problema é que eu tinha regras no .htaccess que não consigo portar para o Nginx. Tentei diversas coisas sem sucesso.

Minha URL original é www.meusite.com.br?pg=servicos e usando o htaccess ela fica www.meusite.com.br/servicos

Pego essa parametro "servicos" para usar na minha consulta. No apache vai de boa com este código:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?pg=$1

No nginx não consigo. Estou testando agora com:

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

        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name meusite.com.br www.meusite.com.br;

        location / {
                try_files $uri $uri/ /?pg=$args;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

Se alguém puder dar uma dica... 

 

Muito obrigado pessoal.

Link to comment
Share on other sites

Tentei alguns desses, todos sem sucesso.

No geral eles mandam usar isto:

location / {
        if (!-e $request_filename){
                rewrite ^(.*)$ /?pg=$1;
        }
}

Ou isto:

location / {
        if ($rule_0 = "21"){
                rewrite ^/(.*)$ /?pg=$1;
        }
}

Nenhum funcionou. Já tentei dentro e fora do location.. nenhum dá resultado algum.

Link to comment
Share on other sites

3 minutos atrás, Rocha Neto disse:

Acho que eu me expressei errado. Tem que converter.

exato rsrs
tem que usar as expressões do nginx para fazer a mesma função, sorte é que tem vários na internet que converte sozinho para praticidade hihi

Chamou? Estamos ai!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...

Important Information

Do you agree with our terms?