安裝配置如下:
/etc/nginx 目錄

/home/nginx目錄

--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_module
安裝Nginx時報錯
下圖是沒有添加任何配置參數的截圖:./configure

[emerg]: getpwnam(“nginx”) failed
--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。
--sbin-path=<path> - Nginx可執行文件安裝路徑。只能安裝時指定,如果沒有指定,默認為<prefix>/sbin/nginx。
--conf-path=<path> - 在沒有給定-c選項下默認的nginx.conf的路徑。如果沒有指定,默認為<prefix>/conf/nginx.conf。
--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
浙公網安備 33010602011771號