设置nginx以支持自定义域名

时间:2016-01-17 01:58:10

标签: nginx dns webserver cname

我有一个在基于Debian的Ubuntu作为操作系统的VM上托管的Django Web应用程序,以及nginx反向代理+ gunicorn作为Web服务器。

此Web应用程序的DNS为myapp.cloudapp.net。我还有一个ccTLD mydomain.pk我需要配置为此Web应用程序的自定义域名。

我的原始注册商仅支持域名服务器。因此,我在dns.he.net(一个免费的DNS托管服务提供商)上创建了一个帐户来托管我的名字服务器,并为我的机器设置了CName。

我的问题是,一旦我将CName设置为指向我的网络应用程序的DNS,在浏览器中输入mydomain.pk只会向我显示一个通用的Welcome to ngnix!页面。然而,在浏览器中输入myapp.cloudapp.net(或myapp.cloudapp.net:80)会正确打开Web应用程序。为什么没有设置CName工作?

我已经与dns.he.net的支持人员交谈了 - 我被告知我的CName设置正确,并且我的nginx配置可能存在一些问题。

例如,这是我的etc/nginx/sites-available/myproject文件:

server {
    listen 80;
    server_name myapp.cloudapp.net;
    charset utf-8;
    underscores_in_headers on;
    location = /favicon.ico { access_log off; log_not_found off; }

    location /static/ {

        root /home/myuser/projectpk/project;
    }

    location /static/admin {

        root /home/myuser/.virtualenvs/projectpk/local/lib/python2.7/site-packages/django/contrib/admin/static/;
    }

    location / {
        proxy_pass_request_headers on;
        proxy_buffering on;
        include proxy_params;
        proxy_pass          http://unix:/home/myuser/projectpk/project/project.sock;
    }


    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /home/myuser/projectpk/project/templates/;
    }
}

1 个答案:

答案 0 :(得分:1)

删除main行,nginx中不需要它,除非您想根据收到的主机名提供不同的内容。

如果删除该行,nginx将回答在适当的端口(在本例中为80)到达服务器的任何请求,public static void main(String[] args) { // initialize string String str1; Scanner sc = new Scanner(System.in); // scanner reads string System.out.print("Enter a sentence"); str1 = sc.next(); System.out.println(str1); // create and set up frame JFrame frame = new JFrame("Characters in Text field :"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create text fields with a single character for(int i = 0; i < str1.length(); i++) { JTextField tf = new JTextField(4); char ch = str1.charAt(i); // output the character for debugging? System.out.println(ch); // set the newly created text fields text to ch tf.setText(ch + ""); // add the text field to frame while it's still in scope frame.add(tf); } // let frame's layout manager do it's thing frame.pack(); // show the frame frame.setVisible(true); } server_name中的myapp.cloudapp.net报头中。

这假设在/ etc / nginx / sites-enabled中没有其他配置可以捕获请求。

相关问题