V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
caixuanxu
V2EX  ›  问与答

nginx 启动问题

  •  1
     
  •   caixuanxu · 2018-03-27 15:24:42 +08:00 · 1639 次点击
    这是一个创建于 2221 天前的主题,其中的信息可能已经有所发展或是发生改变。

    nginx: [emerg] bind() to 0.0.0.0:38022 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:38022 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:38022 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:38022 failed (48: Address already in use) nginx: [emerg] bind() to 0.0.0.0:38022 failed (48: Address already in use) nginx: [emerg] still could not bind()

    这个怎么解决我换了几个接口也是一样的

    22 条回复    2018-03-27 17:26:31 +08:00
    lizhimiao
        1
    lizhimiao  
       2018-03-27 15:33:23 +08:00
    把配置文件贴出来看看.
    hadoop
        2
    hadoop  
       2018-03-27 15:34:26 +08:00
    sudo lsof -i :38022 看下端口被谁占用了呗
    caixuanxu
        3
    caixuanxu  
    OP
       2018-03-27 15:35:46 +08:00
    @hadoop 就是 nginx 本身
    caixuanxu
        4
    caixuanxu  
    OP
       2018-03-27 15:35:55 +08:00
    @lizhimiao
    #user nobody;
    worker_processes 1;

    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    #pid logs/nginx.pid;


    events {
    worker_connections 1024;
    }


    http {
    include mime.types;
    default_type application/octet-stream;

    #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    # '$status $body_bytes_sent "$http_referer" '
    # '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log logs/access.log main;

    sendfile on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout 65;

    #gzip on;

    server {
    listen 38022;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location /a {
    root html;
    index index.html index.htm;
    proxy_pass http://localhost:28080;
    }
    #location /apis {
    #rewrite ^.+apis/?(.*)$ /$1 break;
    #include uwsgi_params;
    #proxy_pass http://localhost:28080;
    #}
    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}


    # HTTPS server
    #
    #server {
    # listen 443 ssl;
    # server_name localhost;

    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    # ssl_session_cache shared:SSL:1m;
    # ssl_session_timeout 5m;

    # ssl_ciphers HIGH:!aNULL:!MD5;
    # ssl_prefer_server_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}
    include servers/*;
    }
    caixuanxu
        5
    caixuanxu  
    OP
       2018-03-27 15:36:32 +08:00
    @lizhimiao 我在做跨域的 一直失败
    ik
        6
    ik  
       2018-03-27 15:38:42 +08:00 via iPhone
    这是用的 restart 吧? killall nginx 再启动呢?
    caixuanxu
        7
    caixuanxu  
    OP
       2018-03-27 15:40:01 +08:00
    @ik 一样的 有 QQ 吗 加个聊
    加完后我会把留言删了
    Lax
        8
    Lax  
       2018-03-27 15:43:36 +08:00
    @caixuanxu lsof -i :38022 结果里还有 socket 状态,也看一下。有可能是还没有回收完成
    lizhimiao
        9
    lizhimiao  
       2018-03-27 15:45:10 +08:00
    include servers/*;

    这个目录下有配置文件吗?
    caixuanxu
        10
    caixuanxu  
    OP
       2018-03-27 15:45:19 +08:00
    @Lax 关进程没有关系 就算 K 掉 还是会起来
    caixuanxu
        11
    caixuanxu  
    OP
       2018-03-27 15:45:35 +08:00
    @lizhimiao 没有
    ik
        12
    ik  
       2018-03-27 15:55:24 +08:00
    企鹅: MTA1NDc1Nzk=
    渣渣一个,不一定能解决哈....

    看 #10 的回复, 我觉得你应该把 #8 这个问题搞明白, nginx 有守护进程?
    caixuanxu
        13
    caixuanxu  
    OP
       2018-03-27 15:58:32 +08:00
    @ik 有解决的办法吗
    menghuan
        14
    menghuan  
       2018-03-27 15:58:55 +08:00
    你的 nginx 启动脚本有问题吧 重启时候没有杀死之前的进程
    caixuanxu
        15
    caixuanxu  
    OP
       2018-03-27 16:00:20 +08:00
    @menghuan 我重启电脑 就不存在之前的进程了 可是还是同样的错
    ik
        16
    ik  
       2018-03-27 16:04:36 +08:00
    @caixuanxu
    ```
    1. ps 命令 先记下 nginx 主进程的 PID
    2. killall nginx
    3. 再 ps 看下是否有 nginx 主进程 PID 是否一致, 要是一致说明没有 kill 掉, 要是不一样, 那可能是有守护进程已经重启了, 可以试试新配置是否生效
    ```
    caixuanxu
        17
    caixuanxu  
    OP
       2018-03-27 16:08:17 +08:00
    @ik 这些我都做过了
    ik
        18
    ik  
       2018-03-27 16:11:15 +08:00 via iPhone
    @caixuanxu 目前也只能想到这样了, 你做过了。。。那么结论呢?
    ik
        19
    ik  
       2018-03-27 16:11:51 +08:00 via iPhone
    @caixuanxu 这些操作的结果。。。
    caixuanxu
        20
    caixuanxu  
    OP
       2018-03-27 16:15:55 +08:00
    @ik 配置的问题 杀进程肯定是不对的
    vindurriel
        21
    vindurriel  
       2018-03-27 17:15:51 +08:00 via iPhone
    配置贴全了嘛 include servers/* 这里有吗?
    csl1995
        22
    csl1995  
       2018-03-27 17:26:31 +08:00
    netstat -nlp|grep
    kill 9 pid
    systemctl restart nginx
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3733 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:35 · PVG 18:35 · LAX 03:35 · JFK 06:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.