天天看點

非root使用者安裝nginx

衆所周知,apache的80端口為系統保留端口,如果通過其他非root使用者啟動,會報錯如下:

nginx: [emerg] bind() to 0.0.0.0:80 failed(13: Permission denied)

因為普通使用者隻能用1024以上的端口,1024以内的端口隻能由root使用者使用。

普通使用者在restart和reload nginx時,會報錯:nginx:[warn] the "user" directive makes sense only if the master processruns with super-user privileges, ignored in/home/tomcat/nginx/conf/nginx.conf:2

原因是:預設情況下linux的1024以下端口是隻有root使用者才有權限占用

方法一:

所有使用者都可以運作(因為是755權限,檔案所有者:root,組所有者:root)

chown root:root nginx

chmod 755 nginx

chmod u+s nginx

方法二:

僅 root 使用者和 test 使用者可以運作(因為是750權限,檔案所有者:root,組所有者:test)

chown root:test nginx

chmod 750 nginx

<code>chmod u+s 就是給某個程式的所有者以suid權限,可以像root使用者一樣操作。</code>

<code>Set uid, gid,sticky bit的三個權限的詳細說明</code>

<code> </code> 

<code>一個檔案都有一個所有者, 表示該檔案是誰建立的. 同時, 該檔案還有一個組編号, 表示該檔案所屬的組, 一般為檔案所有者所屬的組.</code>

<code>如果是一個可執行檔案, 那麼在執行時, 一般該檔案隻擁有調用該檔案的使用者具有的權限. 而setuid, setgid 可以來改變這種設定.</code>

<code>setuid: 設定使檔案在執行階段具有檔案所有者的權限. 典型的檔案是 /usr/bin/passwd. 如果一般使用者執行該檔案, 則在執行過程中, 該檔案可以獲得root權</code>

<code>限, 進而可以更改使用者的密碼.</code>

<code>setgid: 該權限隻對目錄有效. 目錄被設定該位後, 任何使用者在此目錄下建立的檔案都具有和該目錄所屬的組相同的組.</code>

<code>sticky bit: 該位可以了解為防删除位. 一個檔案是否可以被某使用者删除, 主要取決于</code>

<code>該檔案所屬的組是否對該使用者具有寫權限. 如果沒有寫權限, 則這個目錄下的所有檔案都不能被删除, 同時也不能添加新的檔案. 如果希望使用者能夠添加檔案</code>

<code>但同時不能删除檔案, 則可以對檔案使用sticky bit位. 設定該位後, 就算使用者對目錄</code>

<code>具有寫權限, 也不能删除該檔案.</code>

<code>下面說一下如何操作這些标志:</code>

<code>操作這些标志與操作檔案權限的指令是一樣的, 都是 chmod. 有兩種方法來操作,</code>

<code>1) chmod u+s temp —為temp檔案加上setuid标志. (setuid 隻對檔案有效)</code>

<code>chmod g+s tempdir —為tempdir目錄加上setgid标志 (setgid 隻對目錄有效)</code>

<code>chmod o+t temp —為temp檔案加上sticky标志 (sticky隻對檔案有效)</code>

<code>2) 采用八進制方式. 對一般檔案通過三組八進制數字來置标志, 如 666, 777, 644等. 如果設定這些特殊标志, 則在這組數字之外外加一組八進制數字. 如</code>

<code>4666, 2777等. 這一組八進制數字三位的意義如下,</code>

<code>abc</code>

<code>a - setuid位, 如果該位為1, 則表示設定setuid</code>

<code>b - setgid位, 如果該位為1, 則表示設定setgid</code>

<code>c - sticky位, 如果該位為1, 則表示設定sticky</code>

<code>設定完這些标志後, 可以用 ls -l 來檢視. 如果有這些标志, 則會在原來的執行标志位置上顯示. 如</code>

<code>rwsrw-r– 表示有setuid标志</code>

<code>rwxrwsrw- 表示有setgid标志</code>

<code>rwxrw-rwt 表示有sticky标志</code>

<code>那麼原來的執行标志x到哪裡去了呢? 系統是這樣規定的, 如果本來在該位上有x, 則這些特殊标志顯示為小寫字母 (s, s,t). 否則, 顯示為大寫字母 (S, S, T)</code>

<code>yum -y install zlib-devel opensslopenssl-devel</code>

<code>useradd -M -s /sbin/nologin nginx</code>

<code> </code><code>---------配置編譯安裝-------- cd /opt/nginx-1.2.8/</code>

<code>./configure \</code>

<code>--prefix=/home/tomcat/nginx \                                                                                   </code>

<code>--user=tomcat \</code>

<code>--group=tomcat \</code>

<code>--error-log-path=/home/tomcat/nginx/nginxvar/nginx-log/error.log\</code>

<code>--http-log-path=/home/tomcat/nginx/nginxvar/nginx-log/access.log\                                              </code>

<code>--pid-path=/home/tomcat/nginx/nginxvar/nginx-run/nginx.pid\                                                    </code>

<code>--lock-path=/home/tomcat/nginx/nginxvar/nginx-lock/nginx.lock\</code>

<code>--with-http_ssl_module \</code>

<code>--with-http_flv_module \</code>

<code>--with-http_stub_status_module \</code>

<code>--with-http_gzip_static_module \</code>

<code>--with-pcre=/home/tomcat/nginx/nginxvar/pcre-8.40</code>

      本文轉自ling118 51CTO部落格,原文連結:http://blog.51cto.com/meiling/1894890,如需轉載請自行聯系原作者

繼續閱讀