安裝nginx
首先須要安裝pcre庫
2.解壓 tar -zxvf pcre-8.40.tar.gz
3.進入安裝包目錄 cd pcre-8.40
4.編譯安裝./configure
make && make install
5.查看PCRE版本pcre-config --version
安裝nginx
2.解壓 tar -zxvf nginx-1.14.0.tar.gz
3.切換到安裝目錄cd nginx-1.14.0
4../configure --prefix=/root/data/nginx1 後面跟的路徑是它的安裝路徑
5.echo $?
6.make && make install
7.echo $?
8.cd /root/data/nginx1/
9.ls # 安裝完成
conf html logs sbin
建立nginx的主配置文件,由於咱們不使用nginx自帶的配置文件:
1.mv nginx.conf nginx.conf.bak ##對配置文件進行備份
2.vim nginx.conf # 內容以下
user nobody nobody;
worker_processes 2;
error_log /root/data/nginx1/logs/nginx_error.log crit;
pid /root/data/nginx1/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /root/data/nginx1/client_body_temp;
proxy_temp_path /root/data/nginx1/proxy_temp;
fastcgi_temp_path /root/data/nginx1/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
add_header Access-Control-Allow-Origin *;
include vhost/*.conf;
}
3.mkdir vhost # 建立虛擬主機配置文件的存放目錄
4.cd vhost
upstream 192.168.204.134{
# 須要負載的server列表,能夠直接使用ip
server 192.168.204.134:9999 weight=1;
server 192.168.204.134:9080 weight=3;
}
server{
listen 80;
autoindex on;
server_name 192.168.204;
access_log /root/data/nginx1/logs/access.log combined;
index index.html index.htm index.jsp;
location / {
add_header Access-Control-Allow-Origin *;
}
}
3.檢查nginx配置文件,顯示沒問題則啓動nginx服務:
1.cd /root/data/nginx1/sbin
2. ./nginx -t # 檢查nginx配置文件
nginx: the configuration file /root/data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /root/data/nginx/conf/nginx.conf test is successful
3../nginx -c /root/data/nginx1/conf/nginx.conf # 啓動nginx服務
4.netstat -lntp | grep nginx # 檢查端口是否已監聽
5.ps aux |grep nginx # 檢查nginx進程是否正常