Nginx Rewrite all http request to www -


my question similar 1 here . in case using godaddy public domain name, points public address , routed server have fixed private ip address (192.168.0.145).if give server name domain.com in nginx.conf, nothing works. if give localdomain or server private ip works if browse http://domain.com. try adding domain name host fail [127.0.0.1 domain_name] no luck. searched through web never seen 1 placing private ip or localdomain in nginx.conf instead of domain address. need redirect http://domain.name http://www.domain.com, since cannot place domain name couldn't find solution it. missing obvious?

server {         listen 80;         server_name 192.168.0.145;         location / {             proxy_set_header x-forwarded-host $host;             proxy_set_header x-forwarded-server $host;             proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;             proxy_pass http://localhost:8080;         } } 

this tricky solution, define 2 servers, , non-www redirects www

server{     server_name domain.com;     return 301 $scheme://www.domain.com$request_uri } server{     server_name www.domain.com;     #the rest of normal config goes here } 

all non-www match server#1 , directed format matches server#2


Comments