我是靠谱客的博主 大气高山,这篇文章主要介绍nginx服务器搭建和配置详解,现在分享给大家,希望可以做个参考。

一、安装编译工具及库文件

依赖库安装,一定要按照顺序安装:

(1) 如果没有安装c++编译环境

复制代码
1
yum install gcc-c++

(2) ssl 功能需要 openssl 库

复制代码
1
2
3
4
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz tar -zxvf openssl-1.1.0f.tar.gz cd openssl-1.1.0f ./config make && make install

(3) rewrite 模块需要 pcre 库

复制代码
1
2
3
4
wget https://ftp.pcre.org/pub/pcre/pcre-8.01.tar.gz tar -zxvf pcre-8.01.tar.gz cd pcre-8.01 ./configure make && make install

(4) gzip 模块需要 zlib 库

复制代码
1
2
3
4
wget https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make && make install

(4) nginx安装

复制代码
1
2
3
4
wget http://nginx.org/download/nginx-1.12.1.tar.gz tar -zxvf nginx-1.12.1.tar.gz cd nginx-1.12.1 ./configure --prefix=/usr/local/nginx make && make install

二、设置依赖库连接

如果输入语句:./usr/local/nginx/sbin/nginx出现错误:

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

可输入:

whereis libpcre.so.1

结果:libpcre.so: /lib64/libpcre.so.1 /usr/local/lib/libpcre.so /usr/local/lib/libpcre.so.0

再使用ln命令,将libpcre.so.0,libpcre.so和libpcre.so.1连接到lib64目录下:

复制代码
1
ln -s /usr/local/lib/libpcre.so.0 /lib64

三、Nginx 配置

创建 Nginx 运行使用的用户 www:

复制代码
1
2
/usr/sbin/groupadd www /usr/sbin/useradd -g www www

配置ngix.conf, 输入:vi /usr/local/webserver/nginx/conf/nginx.conf的内容修改为:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
user www www; worker_processes 2; error_log ../error.log; pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 80;//端口 server_name localhost;//域名 index test.html index.htm index.php;//解析网页名称 root /usr/local/nginx/html; #站点目录 location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d; # access_log off; } location ~ .*\.(js|css)?$ { expires 15d; # access_log off; } access_log off; } }

检查配置是否正确:

复制代码
1
/usr/local/webserver/nginx/sbin/nginx -t

启动:/usr/local/webserver/nginx/sbin/nginx

监听进程:ps -ef|grep nginx

访问服务器IP: 192.168.1.23

这里写图片描述

问题:配置正确时,也会出现IP地址无法访问的情况:

可以通过阿里云服务器,esc服务器->安全组->配置规则->添加规则,进行配置即可。

这里写图片描述

这里写图片描述

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

最后

以上就是大气高山最近收集整理的关于nginx服务器搭建和配置详解的全部内容,更多相关nginx服务器搭建和配置详解内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(183)

评论列表共有 0 条评论

立即
投稿
返回
顶部