yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl \
zlib*
nginx1.21.6版本链接:https://pan.baidu.com/s/1ggoD250o1HgdDqYdzkbZtw
提取码:spnm
cd nginx-1.21.6/
进行相关配置,指定安装目录,启用http_stub_status_module统计模块(统计多少人访问)
./configure \
> --prefix=/usr/local/nginx \
> --with-http_stub_status_module
安装
make && make install
以便管理员直接执行“nginx”命令就可以调用Nginx的主程序为主程序nginx以及配置文件创建连接文件,以便管理员直接执行“nginx”命令就可以调用Nginx的主程序
ln -s /usr/local/nginx/conf/nginx.conf /etc/
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
检测nginx配置文件是否正常
nginx -t
启动nginx
nginx
浏览器输入服务器公网ip地址显示如下信息代表安装成功

vim /usr/local/nginx/conf/nginx.conf
在配置文件的server对象后面追加新的server对象,其中一个server对象代表一个项目,一个项目一个域名
server {
listen 80;
server_name a.baidu.com;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
root /www/wwwroot/tp5;
index index.php index.html index.htm;
}
}
server {
listen 80;
server_name b.baidu.com;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
root /www/wwwroot/laravel;
index index.php index.html index.htm;
}
}
server对象中的server_name 表示你备案通过的域名
location对象中的root表示你的项目的路径
location对象中的index表示使用域名时的默认访问文件
cd /etc/systemd/system
vi nginx.service
讲一下内容粘贴到nginx.service文件中
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable nginx