如何在Nginx中配置.htaccess

时间:2019-03-29 18:41:13

标签: php nginx mod-rewrite

我正在设置一个新的vps服务器nginx,php-fpm(php 7.2)。 在旧服务器上,我在.htaccess

中具有以下内容
RewriteEngine on
RewriteBase /
RewriteRule index\.html$ index.php [NC]
RewriteRule Share-(.*)\.html$ index.php?a=Share&i=$1 [NC]
RewriteRule ^news-(.*)\.html$ index.php?a=news&i=$1 [L,NC]

nginx conf

server {
    listen   80;
    server_name  mysite.com;
    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;
    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html/mysite;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html/mysite/;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_read_timeout 300;

    }
}

现在,它在nginx中不起作用。如何将此.htaccess转换为nginx?

0 个答案:

没有答案