nginx:[emerg] host找不到" localhost:8004" "听"指示

时间:2015-07-26 14:09:14

标签: django nginx gunicorn

我正在使用nginxgunicorn开发一款支持django的应用程序。 一切都很好,直到今天我试图重新启动失败的nginx。所以我用sudo nginx -t命令测试了它,我收到了这个错误。

nginx: [emerg] host not found in "localhost:8004" of the "listen" directive in
/etc/nginx/sites-enabled/808:2 
nginx: configuration file /etc/nginx/nginx.conf test failed

这是808配置文件内容:

server {
    listen localhost:8004;
    error_log /var/www/html/burger808/error.log;

    location / {
        proxy_pass http://127.0.0.1:8005;
        proxy_set_header X-Forwarded-Host     $server_name;
        proxy_set_header X-Real-IP        $remote_addr;
        add_header P3P 'CP="ALL DSP COR   PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }

    location /static/ {
        autoindex on;
        alias /var/www/html/burger808/burger808/static/;
    }
    location /media/ {
        autoindex on;
        alias /var/www/html/burger808/burger808/media/;
    }
}

我认为可能在8004端口上存在一些冲突。所以我检查了其他的congfig文件,没有冲突。

我想知道可能导致此错误的原因是什么?

3 个答案:

答案 0 :(得分:7)

不需要listen 8004; 。只需要

Imports System
Imports System.Data
Imports MySql.Data.MySqlClient

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

         Using SQLConnection = New MySqlConnection("Server=www.server.com.au;Database=dbtest;Uid=dbtest;Pwd=dbtest;")
            Dim sqlCommand As New MySqlCommand()

            sqlCommand.CommandText = "INSERT INTO test (`test`) values (@test)"
            sqlCommand.Connection = SQLConnection

            Dim DateOrdered As New MySqlParameter("@test", MySqlDbType.Date, 0)
            DateOrdered.Value = DateTimePicker1.Value.ToString("yyyy-MM-dd")

            Try
                SQLConnection.Open()
                Try
                    sqlCommand.Prepare()
                    sqlCommand.ExecuteNonQuery()

                Catch ex As Exception
                    MessageBox.Show("Query: " & ex.Message)
                End Try
            Catch ex As MySqlException
                MsgBox("SQLConnection: " & ex.Message.ToString)
            Finally
                SQLConnection.Close()
            End Try
        End Using

    End Sub
End Class

答案 1 :(得分:0)

smart answer是我的解决方案

  

我假设您正在运行Linux,并且您正在使用gEdit进行编辑   你的文件。在/etc/nginx/sites-enabled中,它可能会留下一个临时值   例如文件default~(观看~)。删除此文件,它会   解决你的问题。

答案 2 :(得分:0)

我的问题是我试图将自定义主机“ my-website.test”添加到nginx配置。
我首先要做的是修改我的/etc/hosts并在其中添加“ my-website.test”。
之后,我的nginx成功运行了。

相关问题