Nginx配置文件

时间:2014-08-03 12:16:52

标签: .htaccess nginx

我对Nginx很陌生,我正在测试这是否是未来的方式。在我的服务器上有几个网站。我设法正确设置了Nginx。但是,在旧设置中有一个.htaccess文件,可确保所有网址都正常工作。

这是.htaccess文件:

RewriteEngine on
RewriteBase /

RewriteRule ^verzekeringen/([a-z]+)$ products/product/index.php?page=$1 [L]
RewriteRule ^hypotheken/([a-z]+)$ products/product/index.php?page=$1 [L]

RewriteRule ^verzekeringen$ products/index.php?type=1 [L]
RewriteRule ^hypotheken$ products/index.php?type=2 [L]

在线转换器,将其转换为:

# nginx configuration
location /verzekeringen {
    rewrite ^/verzekeringen/([a-z]+)$ /products/product/index.php?page=$1 break;
}
location /hypotheken {
    rewrite ^/hypotheken/([a-z]+)$ /products/product/index.php?page=$1 break;
}
location = /verzekeringen {
    rewrite ^(.*)$ /products/index.php?type=1 break;
}
location = /hypotheken {
    rewrite ^(.*)$ /products/index.php?type=2 break;
}

在标准配置文件中,有一部分,我认为应该是。但问题是,我真的不知道如何将其合并到文件中。

server {
    server_name testwebsite.nl www.testwebsite.nl;

    root /var/www/testwebsite.nl/htdocs;

    location ~ \.php$ {
        root           /var/www/testwebsite.nl/htdocs;
        fastcgi_pass   ***.*.*.*:****;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}

2 个答案:

答案 0 :(得分:1)

您实际上可以按照~ \.php$规则之前的任何位置粘贴生成的规则。

你也可以尝试折叠:

server {
    server_name testwebsite.nl www.testwebsite.nl;

    root /var/www/testwebsite.nl/htdocs;

    location /verzekeringen {
       rewrite ^/verzekeringen/([a-z]+)$ /products/product/index.php?page=$1 break;
    }
    location /hypotheken {
       rewrite ^/hypotheken/([a-z]+)$ /products/product/index.php?page=$1 break;
    }
    location = /verzekeringen {
       rewrite ^(.*)$ /products/index.php?type=1 break;
    }
    location = /hypotheken {
       rewrite ^(.*)$ /products/index.php?type=2 break;
    }

    location ~ \.php$ {
        root           /var/www/testwebsite.nl/htdocs;
        fastcgi_pass   ***.*.*.*:****;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

} 

答案 1 :(得分:0)

请参阅指令locationrewrite

location ~ ^/verzekeringen$ {
   rewrite ^(.*)$ /products/index.php?type=2 last;
 }

 location ~ ^/hypotheken$ {
   rewrite ^(.*)$ /products/index.php?type=1 last;
 }

 location ~ /verzekeringen/[a-z]+$ {
   rewrite ^/verzekeringen/(.*)$ /products/product/index.php?page=$1 last;
 }

 location ~ /hypotheken/[a-z]+$ {
   rewrite ^/hypotheken/([a-z]+)$ /products/product/index.php?page=$1 last;
 }