Article Directory
nginx
LAMP/LNMP series environment construction:
Student party white prostitution server-no, no, are you still buying a student computer?
Apache installation and configuration (Windows and Linux)
-you can install and configure MySql Linux-have you lost your studies?
PHP installation and configuration (Windows and Linux)-one article is enough.
Nginx installation and configuration (Window and Linux)-package teaching package.
I know there are integrated software and pagodas, but I want to take it step by step, knowing it, and knowing why .
You don't know that I have been tortured for a long time, and there are some pits that I have never stepped on before.
Windows
1. Download
http://nginx.org/en/download.html
2. Unzip
3. Configuration
4. Start the service
start nginx #启动Nginx
tasklist /fi "imagename eq nginx.exe" #查看进程
nginx -s reload #重启
nginx -s quit #关闭
5. Test
Visit http://localhost:90/
if you don’t use PHP, you can skip below
6. Configure with php
PHP configuration installation reference here
①Open php.ini, searchextension_dirwithcgi.fix_pathinfoAnd modify it accordingly, and then copy a copy to C:/Windows .
②Open nginx.conf
③Create a new test.pgp in the root directory of your website (D:\tools\nginx-1.18.0\html)
as follows:
<?php
echo "记得三连~";
phpinfo();
?>
④Open nginx and php-cgi services
D:
cd tools/nginx-1.18.0 #切到对应目录下
start nginx #启动Nginx
D:\tools\php7\php-cgi.exe -b 127.0.0.1:9000 -c D:\tools\php7\php.ini #启动php-cgi
⑤Access to test http://localhost:90/test.php
Linux
1. Download and unzip
cd /usr/local/src/ #切换目录
wget http://nginx.org/download/nginx-1.18.0.tar.gz #下载包
tar zxf nginx-1.18.0.tar.gz #解压
2. Installation
cd nginx-1.18.0 #进到解压文件
./configure --prefix=/usr/local/nginx #配置编译
make && make install #编译安装
3. Configuration
vim /usr/local/nginx/conf/nginx.conf #编辑配置文件
:wq #保存退出(先按ESC)
The modified content is similar to Windows
4. Script
Convenient management service
vim /etc/init.d/nginx #然后复制下面内容,:Wq保存退出
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
chmod 755 /etc/init.d/nginx #设置权限
chkconfig --add nginx #加入服务启动项
chkconfig nginx on #开机启动
5. Start the service and test
service nginx start #启动服务
ps -ef|grep nginx #查看nginx进程
Access test
6. Configure with PHP
Similarly, if you don't use PHP, you can skip the following. Nginx is already deployed.
PHP configuration installation reference
here①php-fpm related and start
vim /usr/local/php-fpm/etc/php-fpm.conf #编辑配置,复制以下内容(:wq保存退出)
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
cp /usr/local/src/php-7.4.10/php.ini-development /usr/local/php-fpm/etc/php.ini #拷贝
cp /usr/local/src/php-7.4.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #拷贝
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf #拷贝并重命名default
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
chmod 755 /etc/init.d/php-fpm #授权
useradd -s /sbin/nologin php-fpm #添加用户组
service php-fpm start #启动!!!
②Modify nginx configuration
vim /usr/local/nginx/conf/nginx.conf #编辑配置文件
:wq #保存退出(先按ESC)
③Create test.pgp on the webpage and directory
vim /usr/local/nginx/html/test.php #在网页目录下建测试文件
#复制以下内容 (:wq保存退出)
<?php
echo "记得三连~";
phpinfo();
?>
④Access test
The original is not easy, please
donot reprint (this is not a wealthy visits worse) the
blogger's homepage: https://blog.csdn.net/qq_45034708
If the article is helpful to you, remember to follow, like and collect ❤