This is inspired by Install Nginx on Ubuntu and I did it after setting up Ubuntu as per Ubuntu Tips .
Due to WSL limitations (systemd not yet available, see Issues in WSL with systemd, ufw, etc.), to start Nginx in WSL you must use SystemV’s service command to invoke the nginx script in etc.init.d.
systemd
service
nginx
etc.init.d
Example: here we see that the nginx script does live in etc.init.d, and that it gets started in WSL:
alex@CC-Labs-2:/etc/nginx$ ls /etc/init.d apparmor cryptdisks iscsid multipath-tools plymouth-log ssh x11-common apport cryptdisks-early keyboard-setup.sh nginx procps udev atd dbus kmod open-iscsi rsync ufw console-setup.sh hwclock.sh lvm2 open-vm-tools rsyslog unattended-upgrades cron irqbalance lvm2-lvmpolld plymouth screen-cleanup uuidd alex@CC-Labs-2:/etc/nginx$ alex@CC-Labs-2:/etc/nginx$ sudo service nginx help Usage: nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade} alex@CC-Labs-2:/etc/nginx$ alex@CC-Labs-2:/etc/nginx$ sudo service nginx start * Starting nginx nginx [ OK ] alex@CC-Labs-2:/etc/nginx$ alex@CC-Labs-2:/etc/nginx$ sudo service nginx status * nginx is running
Unfortunately, WSL’s nginx script provides less information than normal Linux. For example, in a true Linux system (such as a VM running in Hyper-v), we see a much richer status description:
ubuntu@ccl-vm-1:~$ sudo service nginx status ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2020-05-15 15:03:21 PDT; 50min ago Docs: man:nginx(8) Process: 1087 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 941 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 1095 (nginx) Tasks: 2 (limit: 1075) CGroup: /system.slice/nginx.service ├─1095 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─1096 nginx: worker process May 15 15:03:20 ccl-vm-1 systemd[1]: Starting A high performance web server and a reverse proxy server... May 15 15:03:21 ccl-vm-1 systemd[1]: Started A high performance web server and a reverse proxy server. ubuntu@ccl-vm-1:~$