nginx Rewrite URL problem

Hi guys,

I'm having a problem with the rewrite URL for nginx. It does rewrite the URL but it also changes the location of the root to the default and "Welcome to nginx!" is displayed (instead of the php/html). Here's the code I have in the conf in the sites-enabled folder:

server{
        listen 80; 
        server_name isfollowing.co.uk; 
        rewrite ^/(.*) http://www.isfollowing.co.uk/$1 permanent;
        access_log /var/log/isfollowing.access_log;
        error_log /var/log/isfollowing.error_log;

        location / {
          root /srv/www/isfollowing.co.uk;
          index index.php index.html index.htm;
...
...
}

Test it out at http://isfollowing.co.uk

Anyone know how I can solve this problem? Thanks!

1 Reply

I solved it by adding this code to the nginx.conf:

server {
    listen 80 default;
    server_name _;
    rewrite ^ http://www.$host;
}

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct