linux下普通用戶如何使用80端口啟動程序
http://blog.csdn.net/shootyou/article/details/6750230
大家都知道默認情況下linux的1024以下端口是只有root用戶才有權限占用,於是我們的tomcat,apache,nginx等等程序如果想要用普通用戶來占用80端口的話就會拋出permission denied的異常。
解決辦法有兩種:
1.使用非80端口啟動程序,然后再用iptables做一個端口轉發。
2.假設我們需要啟動的程序是nginx,那么這么做也可以達到目的。
一開始我們查看nginx的權限描述:
-rwxr-xr-x 1 nginx dev 2408122 Sep 5 16:01 nginx
這個時候必然是無法正常啟動的。
首先修改文件所屬用戶為root:
chown root nginx
然后再加上s權限:
chmod u+s nginx
再次查看權限描述的時候:
-rwsr-xr-x 1 root root 2408122 Sep 5 16:01 nginx
這個時候再啟動就沒問題了。
參考:http://bbs.chinaunix.net/thread-2212303-2-1.html
搭建lnmp的時候,nginx都是用root啟動
nginx使用root啟動,所以不需要擔心不夠權限寫入日志
# ps aux|grep nginx
nobody 5672 0.0 0.2 26928 4132 ? S 09:59 0:00 nginx: worker process
root 6318 0.0 0.0 6384 676 pts/0 S+ 10:10 0:00 grep --color nginx
root 27142 0.0 0.0 24444 1652 ? Ss Dec20 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
logs]# ll
total 3596
-rw-r--r-- 1 root root 3665218 Dec 23 10:05 access.log
-rw-r--r-- 1 root root 2667 Dec 23 09:59 error.log
-rw-r--r-- 1 root root 6 Dec 20 16:11 nginx.pid
-rw-r--r-- 1 root root 1178 Dec 20 16:11 nginx_error.log
cd sbin/
[root@VM_45_133_centos sbin]# ll
total 6476
-rwxr-xr-x 1 root root 3454420 Jan 25 2016 nginx
-rwxr-xr-x 1 root root 3166091 Jan 25 2016 nginx.bak