nginx安裝說明

安裝版本:1.10.0

安裝配置以下:html

 

/etc/nginx 目錄nginx

 

/home/nginx目錄dom

 

--prefix=/home/nginx --sbin-path=/usr/sbin/nginx --conf-path=/home/nginx/conf/nginx.conf --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_moduleui

 

安裝Nginx時報錯spa

./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
 
若是報openssl錯誤,安裝openssl-deve就能夠
yum -y install openssl-devel

 

下圖是沒有添加任何配置參數的截圖:./configurerest

 

啓動時若是報錯:

[emerg]: getpwnam(「nginx」) failed

須要添加用戶和用戶組nginx:
adduser -r -M -U nginx



關於安裝配置,官方頁面提供的配置以下:
--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--user=nginx
--group=nginx
--with-http_ssl_module
--with-http_realip_module
--with-http_addition_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_random_index_module
--with-http_secure_link_module
--with-http_stub_status_module
--with-http_auth_request_module
--with-threads
--with-stream
--with-stream_ssl_module
--with-http_slice_module
--with-mail
--with-mail_ssl_module
--with-file-aio
--with-http_v2_module
--with-ipv6

 

相關配置說明以下:日誌

--prefix=<path> - Nginx安裝路徑。若是沒有指定,默認爲 /usr/local/nginx。htm

--sbin-path=<path> - Nginx可執行文件安裝路徑。只能安裝時指定,若是沒有指定,默認爲<prefix>/sbin/nginx。blog

--conf-path=<path> - 在沒有給定-c選項下默認的nginx.conf的路徑。若是沒有指定,默認爲<prefix>/conf/nginx.conf。ip

--pid-path=<path> - 在nginx.conf中沒有指定pid指令的狀況下,默認的nginx.pid的路徑。若是沒有指定,默認爲 <prefix>/logs/nginx.pid。

--lock-path=<path> - nginx.lock文件的路徑,默認爲<prefix>/logs/nginx.lock

--error-log-path=<path> - 在nginx.conf中沒有指定error_log指令的狀況下,默認的錯誤日誌的路徑。若是沒有指定,默認爲 <prefix>/logs/error.log。

--http-log-path=<path> - 在nginx.conf中沒有指定access_log指令的狀況下,默認的訪問日誌的路徑。若是沒有指定,默認爲 <prefix>/logs/access.log。

--user=<user> - 在nginx.conf中沒有指定user指令的狀況下,默認的nginx使用的用戶。若是沒有指定,默認爲 nobody。

--group=<group> - 在nginx.conf中沒有指定user指令的狀況下,默認的nginx使用的組。若是沒有指定,默認爲 nobody。

--builddir=DIR - 指定編譯的目錄

 

配置nginx啓動腳本:

 

將附件中的nginx腳本保存到/etc/init.d/nginx文件,並修改兩個地方:

nginx=」/usr/sbin/nginx」 修改爲nginx執行程序的路徑。

conffile=」/etc/nginx/nginx.conf」 修改爲配置文件的路徑。

保存後,就能夠經過該腳本對nginx服務進行管理了:

使用chkconfig進行管理

上面的方法完成了用腳本管理nginx服務的功能,可是仍是不太方便,好比要設置nginx開機啓動等。這時能夠使用chkconfig來設置。

先將nginx服務加入chkconfig管理列表:

chkconfig --add /etc/init.d/nginx

加完這個以後,就能夠使用service對nginx進行啓動,重啓等操做了。

$ service nginx start
$ service nginx stop
$ service nginx reload
...

設置終端模式開機啓動:

$ chkconfig --level 3 nginx on

 

附件中nginx爲啓動腳本 nginx啓動腳本

 

Centos 7 添加服務啓動方法:

CentOS 7的服務systemctl腳本存放在:/usr/lib/systemd/,有系統(system)和用戶(user)之分,須要開機不登錄就能運行的程序,存在系統服務裏,即:/usr/lib/systemd/system目錄下。

啓動腳本放到路徑/usr/lib/systemd/system/下,執行systemctl enable nginx.service令既能夠完成開機啓動服務的設置

操做服務相關的命令:

設置開機自啓動
systemctl enable nginx.service

手動啓動nginx服務
systemctl start nginx.service

中止開機自啓動
systemctl disable nginx.service

查看服務當前狀態
systemctl status nginx.service

從新啓動服務systemctl restart nginx.service

相關文章
相關標籤/搜索