Restore problem with nginx virtual domain config

8 posts / 0 new
Last post
#1 Fri, 03/29/2013 - 07:44
tradso

Restore problem with nginx virtual domain config

Hello all,

Tried to restore full virtualmin domain backup, but I got error with restoring nginx site config.

Original sites-available/domain.com config file

server {
server_name domain.com;
rewrite ^(.*) http://www.domain.com$1 permanent;
}
server {
server_name www.domain.com;
listen 80;
root /home/domain/public_html;
index index.html index.htm index.php;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
...
fastcgi_param SCRIPT_FILENAME /home/domain/public_html$fastcgi_script_name;

location ~ \.php$ { try_files $uri =404; fastcgi_pass localhost:9002; return 403;}
}

and this is after restoring backup:

server {
server_name /home/domaindomain.com;
rewrite /home/domain^(.*) /home/domainhttp://www.domain.com$1 /home/domainpermanent;
access_log /home/domain/var/log/virtualmin/domain.com_access_log;
error_log /home/domain/var/log/virtualmin/domain.com_error_log;
}

Restored config is not full and also it need to be fixed. Is it a bug?

Fri, 03/29/2013 - 16:52
JamieCameron

This problem here may be that you have two separate server blocks for the domain, which Virtualmin doesn't expect (or create). Is that really necessary?

''

Sat, 03/30/2013 - 05:20
tradso

Maybe. How then nginx config should be for permanent redirect from domain.com to www.domain.com in right way in one server block?

Sat, 03/30/2013 - 11:40 (Reply to #3)
JamieCameron

Check out this page : http://forum.slicehost.com/index.php?p=/discussion/1425/redirect-non-www...

Basically, you just need one server block containing :

if ($host != 'www.site.com' ) {
  rewrite ^/(.*)$ http://www.site.com/$1 permanent;
  }

''

Sat, 03/30/2013 - 18:35 (Reply to #4)
tradso

Yes, I know this config too. But using "if" is a bad practice (according to author of nginx).

Isn't better to use whole file to backup but not content of that file?

Sun, 03/31/2013 - 12:27 (Reply to #5)
JamieCameron

We can't really use the whole file, because on some systems Nginx just has a single config file.

What's the problem with using an if statement?

''

Tue, 04/02/2013 - 08:27
tradso

Okay, maybe is it possible to make an option to backup whole file?

There is no problem with if statement but it's good to follow nginx author recommendations.

Thanks.

Tue, 04/02/2013 - 16:23 (Reply to #7)
JamieCameron

That's kind of tricky to do in a general case, as it is possible for other domains to have server blocks in the same file.

''

Topic locked