安装编译工具和库文件
$ yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
- 下载 PCRE 安装包
$ wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
- 解压安装包
$ tar zxvf pcre-8.35.tar.gz
- 进入安装目录
$ cd pcre-8.35
- 编译安装
$ make && make install```
5. 查看 PCRE 版本<br/>
`$ pcre-config --version`
# 安装 Nginx
1. 下载并解压 Nginx<br/>
```$ wget http://nginx.org/download/nginx-1.15.9.tar.gz
$ tar zxvf nginx-1.9.9.tar.gz```
2. 进入安装目录<br/>
`$ cd nginx-1.9.9`
3. 安装<br/>
```$ ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
$ make
$ make install```
# 配置 Nginx
创建一个用户
$ /usr/sbin/groupadd www
$ /usr/sbin/useradd -g www www
配置其属性
$ vim /usr/local/webserver/nginx/conf/nginx.conf
user www www;
需创建一个用户
worker_processes 2; #设置值和 CPU 核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
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 配置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/javascript text/css application/xml application/x-javascript text/javascript ;
gzip_vary on;
server {
listen 80;
server_name pipe.ccm.ink;#自己的域名
return 301 https://$host;
}
server {# 开启 https
listen 443 ssl;
server_name pipe.ccm.ink;
charset utf-8;
ssl_certificate xxxx.pem;# 换为自己的证书
ssl_certificate_key xxxxx.key;# 换为自己的证书
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#access_log logs/host.access.log main;
location / {
root /home/www/dist/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
检查配置文件正确性
$ /usr/local/webserver/nginx/sbin/nginx -t
# 常用命令
$ /usr/local/webserver/nginx/sbin/nginx # 启动
$ /usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件
$ /usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx
$ /usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于