JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Linux下Nginx安装

wys521 2024-09-06 04:22:57 精选教程 46 ℃ 0 评论

1. 下载地址

http://nginx.org/download/

2. 安装过程

# 1.解压

tar -zxvf nginx-1.9.13.tar.gz

# 2.切换到解压后的目录

cd nginx-1.9.13

# 3.创建组和用户

groupadd -f www

useradd -g www www

# 4.配置(包含HTTP SSL模块)

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

# 5.编译

make

# 6.安装

make install12345678910111213

3. 安装中存在的问题

问题1 ./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using –without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using –with-pcre= option.

解决:yum -y install pcre-devel1

问题2 ./configure: error: the HTTP gzip module requires the zlib library.

You can either disable the module by using –without-http_gzip_module

option, or install the zlib library into the system, or build the zlib library

statically from the source with nginx by using –with-zlib= option.

解决:yum -y install openssl openssl-devel1

问题3 启动后无法访问,但是进程存在,且没有错误日志

解决:# 关闭防火墙 systemctl stop firewalld.service

问题4 启动报错

./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

解决:

# 查找libpcre.so.1

find / -iname "libpcre.so.1"

# 结果

# /software/apache/pcre-8.34/.libs/libpcre.so.1

# /usr/local/lib/libpcre.so.1

# /usr/local/pcre-8.34/lib/libpcre.so.1

# 原因:

# 1.没装PCRE

# 2.PCRE包路径不在LD_LIBRARY_PATH下

# 方法1:设置LD_LIBRARY_PATH中包含pcre包的路径

# 这种方式使用export命令,所以只在本次登录生效

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

# 方法2:nginx默认会从/lib64或/lib下读取libpcre.so.1文件,所以设置软链接即可

ln -s /usr/local/lib/libpcre.so.1 /lib64/ 1234567891011121314151617

4. 常用命令

3.1 启动

cd /usr/local/nginx/sbin

./nginx12

3.2 重启

/usr/local/nginx/sbin/nginx -s reload1

3.3 关闭

#方法1:第一个是完整有序的停止,第二个是快速停止

/usr/local/nginx/sbin/nginx -s quit

/usr/local/nginx/sbin/nginx -s stop

#方法2:

pkill -9 nginx12345

3.4 检测配置文件是否正确

/usr/nginx/sbin/nginx -t1

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表