Heim >Backend-Entwicklung >PHP-Tutorial >Kompilieren Sie Nginx aus dem Quellcode in Centos
groupadd -r nginx
useradd -r -g nginx -s /bin/false -M nginx
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with- http_stub_status_module --with-http_ssl_module --with-pcre --with-http_realip_module --with-http_gzip_static_module --with-file-aio
make && make install
添加启动脚本:vim /etc/init.d/nginx
#!/bin/sh
#
# nginx – dieses Skript startet und stoppt den Nginx-Daemon
#
# chkconfig: - 85 15
# Beschreibung: Nginx ist ein HTTP (S)-Server, HTTP(S)-Reverse
# Proxy und IMAP/POP3-Proxyserver
# Prozessname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# Quellfunktionsbibliothek.
. /etc/rc.d/init.d/functions
# Quellnetzwerkkonfiguration.
. /etc/sysconfig/network
# Überprüfen Sie, ob die Netzwerkverbindung aktiv ist.
[ "$NETWORKING" = " nein" ] && Exit 0
nginx="/usr/local/nginx /sbin/nginx"
prog=$(basename $nginx)
NGINX_ usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockFile =/var/lock/subsys/nginx
make_dirs () {
# Machen Sie die erforderlichen Verzeichnisse
user = `nginx -v 2 & gt; &1 | grep "Argumente konfigurieren:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; dann
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
. fertig
}
Start () {
[ -x $nginx ] || Beenden 5
[ -f $NGINX_CONF_FILE ] || Exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && berühren Sie $lockfile
return $retval
}
stop () {
echo -n $ "stoppt $ prog:"
KillProc $ prog -quit
retval = $?
echo
[$ retval -eq 0 ] && rm -f $lockfile
return $retval
}
🎜> configtest || zurück $?
stoppen
schlafen 1
starten
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
>
force_reload() {
Neustart
configtest() {
$nginx -t. -c $NGINX_CONF_FILE
}
rh_status() {
status 🎜 >}
rh_status_q () {
rh_status & gt;/dev/null 2 & gt; & 1
}
case "$ 1" in
starten)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || Exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || Exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
; ;
condrestart|try-restart)
rh_status_q || Exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
Exit 2
esac
启动脚本到这里介绍.
开启php支持,vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm index.php; //添加index.php
}
//启用下面的配置
Standort ca 🎜> fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}vim /etc /nginx/fastcgi_params,如果没有或者是空白的话,查找一下find / -name fastcgi_params,然后拷贝过来
fastcgi_param GATEWAY_ SCHNITTSTELLE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_meth od;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param content_length $ content_length;
fastcgi_param script_filename $ document_root $ fastcgi_script_name;
fastcgi_name $
fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
Dienst-Nginx-Start
以上就介绍了centos中源码编译nginx, 包括了方面的内容, 希望对PHP教程有兴趣的朋友有所帮助.