WSL: Nginx not start

2016/04/08 11:34:44 [emerg] 10843#0: setsockopt(IPV6_V6ONLY) [::]:80 failed, ignored (22: Invalid argument) 2016/04/08 11:34:44 [emerg] 10843#0: bind() to [::]:80 failed (22: Invalid argument)

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 7
  • Comments: 58 (9 by maintainers)

Most upvoted comments

I got nginx working. Thanks to brilliant @Mocilol solution.

There are 2 separate issues here & 2 separate fixes.

  1. IPV6 Not-Supported: Comment or Remove listen [::]:80 default_server ipv6only=on; at /etc/nginx/sites-available/default
  2. Worker processes issue: Add following lines at /etc/nginx/nginx.conf

master_process off; daemon off;

2.1 When running nginx on master_process, daemon off mode, sudo /etc/init.d/nginx start doesn’t return and if you hit CTRL+C, it gets terminated. Start it in the background using sudo /etc/init.d/nginx start &

Tip: There is no network isolation here (Windows localhost = WSL localhost), so if a windows program like Apache (XAMPP) blocking port 80, you can’t use that port inside WSL. (I heard Skype is using port 80 as well)

As mentioned by @Mocilol and in the following blog post here:

Add the following line to /etc/nginx/nginx.conf: master_process off;

Then restart nginx: sudo service nginx restart;

For some reason when also adding daemon off; as mentioned by @Mocilol; nginx would not restart.

Add this to nginx.conf will let u able to run nginx, enough for development environment: master_process off; daemon off;

@zhaorenjie110 哥们不行啊。我这么做了之后确实没有报错了。但是windows这边还是连接不了nginx,我试了几个端口了,确定没有被使用。

Confirmed that apache2 is working in the latest build with no need to edit any config files.

However, nginx still doesn’t work. I get a slightly different error (FIOASYNC)

2016/05/12 04:07:38 [alert] 354#0: ioctl(FIOASYNC) failed while spawning "worker process" (22: Invalid argument)

Should now be fixed in build 14936. Please let us know if you see this issue persist.

After adding signal driven IO support for unix stream sockets, I was able to run nginx locally and load the default site. Also confirmed that the errors were gone from the nginx error log.

The fix should be out in insider builds soon.

加上这2个master_process off; daemon off;,把运行方式改为TCP模式9000,确实可以运行。不过PHP页面速度太慢,还不如访问虚拟机的速度。

I took a deeper look at ‘Nginx’. It first binds to an IPv4 address and then to an IPv6 address (to the same port by default) using the IPV6_V6ONLY option. Unfortunately, we are not able to support the scenario immediately and we have a bug tracking this. As an alternative, there are couple of options as workarounds: Edit the default configuration of Nginx to start at different ports on IPv4 and IPv6. Or, use either IPv4 or IPv6. The port configuration for Nginx is stored in ‘/etc/nginx/sites-enabled/default’. I was able to verify that both these workarounds work and the Nginx server starts successfully on build 14342. We know its not ideal, but at least gets your one step further. Meanwhile, we have an understanding of the bug on our side, but unfortunately, it might take some time to fix it because of dependencies outside of WSL.

After setting master_process off; within my nginx.conf, I do still get errors within Nginx’s error.log with the following: ioctl(eventfd, FIONBIO) failed (1: Operation not permitted)

However, Nginx has still come up and is accepting connections.

After switching PHP-FPM to over 127.0.0.1:9000 rather than sockets, everything is working perfectly.

This is based on Windows build 14393.5, Nginx 1.11.3 and PHP-FPM (7.0.6).

I have verified that with IPV6ONLY fix and the fix to return EADDRINUSE in bind() when a port is already in use, apache2 starts fine (although it emits a warning around APR_TCP_DEFER_ACCEPT). I was able to connect to the apache webserver port using a browser and access the default page. These fixes should show up soon in the insider builds. Thanks for trying out WSL and providing feedback!

@hanlinking sorry didn’t quite follow your reply, could you please clarify?

By “signal driven IO support for unix stream sockets”, I was referring to nginx’s use of FIOASYNC with F_SETOWNER on a unix stream socket. This combination of syscalls enables SIGIO to be delivered when interesting events happen on the socket. That fix seems to have been the last thing blocking nginx’s default configuration from starting and should be out in an insider build soon.

Still having the same problem. The solution from @dumindaxsb doesn’t work, since I can’t restart, stop, start nginx afterwards. It just gets stuck

With the help of the Windows networking team, we were able to fully implement the IPV6_V6ONLY flag. Hopefully this should resolve a bunch of issues here. The fix is still in our dev branch, but should soon hit the release branch.

Even after long search, I have not found clear answer for choose between Unix socket and TCP when using Nginx+PHP-FPM.

  • In case of Unix socket I get nginx error: 2016/08/19 14:21:49 [alert] 412#0: *3 connect() failed (22: Invalid argument) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost:8080"
  • In case of TCP port it works, but /var/log/php5-fpm.log every second gets line of: [19-Aug-2016 14:31:50] ERROR: failed to retrieve TCP_INFO for socket: Invalid argument (22) This is not production, but I can’t turn it off with php settings, at some point silently spamming, that file will grow huge.

My setup from clean installation:

  • /etc/nginx/nginx.conf: user www-data; master_process off; ... fastcgi_pass {with port or socket};
  • /etc/php5/fpm/pool.d/www.conf: listen.mode = 0660 listen = 127.0.0.1:9009 or listen = /var/run/php5-fpm.sock

If I spoil permissions, then error is different. What would you advise?

@wizardist It works for me on port 80. You can use netstat in powershell to find out what’s blocking your 80.

@aran112000 Indeed, you were right. It’s working fine now with 127.0.0.1:9000 😃 I have a couple of errors though (but doesn’t seem to affect the server)

When I start php-fpm

initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused

In php-fpm log (repeated every second)

[04-Aug-2016 23:52:20] ERROR: failed to retrieve TCP_INFO for socket: Invalid argument (22)

When I start mariadb (should be the same with mysql I suppose)

/lib/lsb/init-functions.d/50-ubuntu-logging: line 5: 6312 Aborted (core dumped) plymouth --ping > /dev/null 2>&1

@luisfavila Yes i did that, but it didn’t resolve the problem, at least not for me

Update: it seams Skype is The problem: Skype automatically updated itself, and turned the “use port 80” option back on. after disabling that on skype i can start nginx without any error but it doesn’t respond in any way.