how to setup subdomain on nginx ubuntu for file hosting

April 16, 2015 3.6k views
Nginx Ubuntu

Hi guys,
i have installed ubuntu 14.0.4 and nginx, as i found article about
How To Set Up nginx Virtual Hosts (Server Blocks) on Ubuntu 12.04 LTS

i did, but the result was failed, because i create index.html, but the result just show me:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

i need help to setup sub domain and create ftp user that able to upload.

i need this server for file hosting of my website that provide direct links for download. any suggestion?

2 Answers

Try changing your listen and server_name directives to:

listen       80  default_server;
server_name  _;

This tells nginx to make your server block the default and respond if no other block matches the Host header. Earlier it would respond only to Host: example.com as defined in the tutorial.

Resource link.

  • Here is the configuration, what should i change in the follow ?
    server {
    listen 80; ## listen for ipv4; this line is default and implied
    #listen [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www/dl.domain.com/public_html;
        index index.html index.htm;
    
        # Make site accessible from http://localhost/
        188.27.10.28 dl.domain.com;
    

    }

If your configuration looks like the one you posted:

server {
    listen 80; ## listen for ipv4; this line is default and implied
    #listen [::]:80 default ipv6only=on; ## listen for ipv6

    root /var/www/dl.domain.com/public_html;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    188.27.10.28 dl.domain.com;
}

Then it's not valid.

You can test your configuration with nginx -t.
After I tested your server block, I get the following error:

$ nginx -t
2015/04/22 00:26:32 [emerg] 145#0: unknown directive "188.27.10.28" in /etc/nginx/nginx.conf:39
nginx: [emerg] unknown directive "188.27.10.28" in /etc/nginx/nginx.conf:39
nginx: configuration file /etc/nginx/nginx.conf test failed

This means that the line 188.27.10.28 dl.domain.com; is not valid. You can remove it or comment it out.

After this reload nginx with nginx reload and try it again.

I keep my fingers crossed that it works for you!

Have another answer? Share your knowledge.