How to enable mod_rewrite on LEMP Ubuntu

August 3, 2016 6.4k views
DigitalOcean Nginx LEMP Ubuntu

I have created a website in a droplet, and I have uploaded sendy files to a subdirectory.
After installing the sendy it gives 404 error.
In their documentation it says that i need to enable mod_rewrite. I have tried all answers here in digitalocean community nothing fixed for me.

Before reading further, please verify that the .htaccess file has been uploaded.

As part of the compatibility checklist, mod_rewrite needs to be enabled.

I tried to edit .htaccess file and tried to add try_files $uri $uri/ /index.php?$args; in server { but nothing worked.

Can anyone help me out with this problem?

5 Answers

Okay, so nginx doesn't use .htaccess, delete it, it's useless.

And it should be

location / {
        try_files $uri $uri/ /index.php?q=$request_uri;

Also make sure php5-fpm or hhvm is working! (depends on what you use)

  • When I add the try_files inside location /{
    it gives fail error when I restart nginx
    On which path and file do I need to give this line? I tried multiple files and everything failed.

    • You might have messed up the config, try resetting the configs and following my instructions above.

      • Where I should put this try_files line?
        which path and which file?
        I don't know where to do all this stuff.
        Can you take a look and help me with this problem?

    • You can run nginx -t to test your nginx configuration as well. Best of luck.

Can someone willing to take a look at my config and help to fix this problem?
Tried everything still the sub-directory is not working properly.

Yes, paste it on, and I'll look at it :-)

  • path /etc/nginx/sites-enabled/(mywebsitefolder)

    I have done this it's going inside now. But the other than that It doesn't goes to any pages like settings, etc. it just stays in index.php

    I think something needs to change in the try_files

Sorry, no idea why it doesn't work :(

Can someone please check and help me out?

Have another answer? Share your knowledge.