OS X - 在80端口启动Nginx
不知道你是怎么在你的mac上安装nginx的,但是如果你跟我一样:
brew install nginx
然后你会发现你的nginx.conf中的端口是8080。
于是你可能像我一样试着把端口改为80,然后reload一下。
你发现没有任何错误提示,当你访问localhost时却没有nginx的首页,甚至连403也没有。
于是你尝试...
sudo lsof -n -i:80 | grep -i LISTEN
却发现没有输出和nginx有关的任何东西。
于是才想起OSX不允许system级以外的服务使用1024以下的端口。
起初我并没有太关心这个问题,我并不介意多输入几个数字。
直到我加入了一个新的团队,我和我那些使用其他操作系统的同事们统一了hosts,并使用同一个数据库进行开发时才意识到 —— 我可能因为这个问题给别人造成麻烦。
launchd
关于launchd的描述,这里引用一下manpage,如下:
launchd manages processes, both for the system as a whole and for individual users.
The primary and preferred interface to launchd is via the launchctl(1) tool which (among other options) allows the user or administrator to load and unload jobs.
Where possible, it is preferable for jobs to launch on demand
based on criteria specified in their respective configuration files.
launchd also manages XPC services that are bundled within applications and
frameworks on the system.
During boot launchd is invoked by the kernel to run as the first process on
the system and to further bootstrap the rest of the system.
You cannot invoke launchd directly.
launchd用于为系统和用户管理进程,主要通过launchctl对其进行操作,用户无法直接调用launchd。
启动时由内核调用launchd,运行第一个进程。
plist
另外我们需要了解的就是plist文件。
plist就是property list format的意思,是苹果用来保存应用数据的格式,其实就是个xml。
可以在 /usr/local/opt/nginx 下找到nginx对应的plist文件,比如在我的电脑上是 homebrew.mxcl.nginx.plist 。
它的内容大概是这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.nginx</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/nginx/bin/nginx</string>
<string>-g</string>
<string>daemon off;</string>
</array>
<key>WorkingDirectory</key>
<string>/usr/local</string>
</dict>
</plist>
我们需要把这个文件复制到 /Library/LaunchDaemons 下,如果是 ~/Library/LaunchAgents 也可以,但两者有区别。
前者是系统启动时启动,后者则是在用户登录时启动。
接着执行launchctl load -w,如下:
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
最后,重启你的机器,你会发现nginx在80端口启动了。
OS X - 在80端口启动Nginx的更多相关文章
- nginx 普通用户使用80端口启动nginx
方法一: 依次执行如下命令 cd /usr/local/nginx/sbin/ chown root nginx chmod u+s nginx 优点是,方便简单,缺点是,既然sudo权限都不给了.这 ...
- Mac OS X 绑定80端口,不装nginx的小技巧
Mac OS X 因为要绑定80端口需要ROOT权限, 但是如果用root权限启动eclipse或tomcat又会造成, 启动创建的各类文件是root的,普通用户无法删除. 为此, 我们可以通过pfc ...
- Linux非root用户如何使用80端口启动程序
默认情况下Linux的1024以下端口是只有root用户才有权限占用,我们的tomcat,apache,nginx等等程序如果想要用普通用户来占用80端口的话就会抛出java.net.BindExce ...
- linux下普通用户如何使用80端口启动程序
linux下普通用户如何使用80端口启动程序 http://blog.csdn.net/shootyou/article/details/6750230 大家都知道默认情况下linux的1024以下端 ...
- 普通用户从非80端口启动tomcat,通过端口转发监听80端口
linux下小于1024的端口都需要root去绑定. root权限启动tomcat是不明智的,可以使用非root权限启动tomcat监听8080端口,然后利用端口转发实现对80端口的监听. 端口转发: ...
- 非root用户在80端口运行nginx
一般情况下没有这种需求,但对于强迫症患者来说,还是完整的走了一把. 普通用户是不允许使用1024以下端口的,所以此次操作仍然需要root权限来进行配置.而且由于使用了root安装,因此nginx用户仍 ...
- Swoole 绑定域名 80 端口 (Nginx 反向代理)
启动 Swoole 的 http server,可以使用 IP + 端口 进行访问 创建 Nginx 虚拟域名 vim swotp.liuguofeng.com.conf server { liste ...
- SELinux配置不当导致httpd无法在非80端口启动
检测是否为selinux导致httpd启动失败,若setenforce 0以后就可以启动,就表示selinux配置不当. 首先本机要支持semanage命令,安装方法网上有. semanage po ...
- 非root启动80端口
Linux非root用户如何使用80端口启动程序 默认情况下Linux的1024以下端口是只有root用户才有权限占用,我们的tomcat,apache,nginx等等程序如果想要用普通用户来占用 ...
随机推荐
- J2EE简介
一,J2EE概念: J2EE的全称为,Java2 Platform Enterprise Edition,Java或java2平台企业版,他是基于java平台或java2平台的标准版,保留并扩展了J2 ...
- 第7月第19天 swift on linux
1. https://github.com/iachievedit/moreswift http://dev.iachieved.it/iachievedit/more-swift-on-linux/ ...
- [转]Restrict关键字
0 定义 C99中新增加的用于修饰指针的关键字,用于表示该指针所指向的内存,只有通过该指针访问得到(如下ptr指向的内存单元只能通过ptr访问得到).从而可以让编译器对代码进行优化,生成更有效率的汇编 ...
- win10下安装MinGW-w64 - for 32 and 64 bit Windows
对于不经常使用c语言的同学来说,只需要安装MinGW-w64 - for 32 and 64 bit Windows,就可以使用GCC在命令行对c源码进行编译. 首先打开命令行检查自己是否已经安装了g ...
- 【源码阅读】VS调试mimikatz-改造法国神器mimikatz执行就获取明文密码
0x1 概要 记得某位同学提起在XXX得到了一个一键生成明文的工具,觉得很是神奇... 然而我一看图标就知道是mimikatz,这工具是开源的,只要改两行代码就可以实现写死命令了. 顺带讲讲编译过程中 ...
- 管中窥豹:从Page Performance看Nand Flash可靠性【转】
转自:https://blog.csdn.net/renice_ssd/article/details/53332746 如果所有的page performace在每次program时都是基本相同的, ...
- MySQL binlog导入失败
一个同事问我,说他用innobackupex恢复数据后用mysqlbinlog导入增量数据时,发现数据没有导入进去并且也没有报错. mysqlbinlog /u01/mysql_py/database ...
- contos 7创建阿里云镜像源
今天在ESC上安装mariaDB,发现centOS 7默认的yum源上的mariaDB版本过低,然后又镜像到网易上,发现网易源上没有mariaDB,几经折腾才发现阿里镜像上mariaDB版本较新.更改 ...
- [USACO14MAR]破坏Sabotage
还是二分答案,发现我的$check$函数不太一样,来水一发题解 列一下式子 $$\frac{sum-sum[l,r]}{n-(r-l+1)}<=ans$$ 乘过去 $$sum-sum[l,r]& ...
- Java并发编程、多线程、线程池…
<实战java高并发程序设计>源码整理https://github.com/petercao/concurrent-programming/blob/master/README.md Ja ...