1、安装Nginx所需要的库、安装pcre库是为了使Nginx支持具备URL重写功能的rewrite模块、如果不安装pcer库,则Nginx无法使用rewrite模块功能,Nginx的rewrite模块功能几乎是企业应用必须的。
yum install pcre pcre-devel openssl openssl-devel -y
2、创建用户
useradd nginx -s /sbin/nologin -M
3、 将下载 好的nginx-1.12.0.tar.gz 解压
tar xf nginx-1.12.0.tar.gz
4、进入解压包
cd nginx-1.12.0
5、创建文件
mkdir /usr/local/nginx1.12
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx1.12/ --with-http_stub_status_module --with-http_ssl_module
6、
make
7
make install
8、
ln -s /usr/local/nginx1.12 /usr/local/nginx //创建软链接方便人员使用、方便以后升级
9、
ls -l /usr/local/nginx/
10、启动前检查配置文件语法
/usr/local/nginx/sbin/nginx -t
11、启动nginx
/usr/local/nginx/sbin/nginx
12、查看Nginx服务对应的端口是否成功启动
lsof -i :80
========================================================================
nginx配置文件内容
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/Club/public;
index index.html index.htm index.php ;
# if (!-e $request_filename) {
#rewrite ^(.*)$ /index.php?s=$1 last;
#break;
#}
# autoindex off;
}
location ~ .*\.(php|php5)?$
{
root html/Club/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}=========================================================================q错误问题
1、启动Nginx时有以下报错
“nginx:[emerg] getpwnam('nginx') failed”这是因为没有对应的Nginx服务用户,执行
useradd nginx -s /sbin/nologin -M
创建Nginx用户即可
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号