nginx 启动问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
caixuanxu
V2EX    问与答

nginx 启动问题

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

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;
#}
}


# anothe 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     Solana     983 人在线   最高记录 6679       Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 25ms UTC 22:35 PVG 06:35 LAX 15:35 JFK 18:35
Do have faith in what you're doing.
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86