参考:http://www.runoob.com/linux/nginx-install-setup.html
https://blog.csdn.net/zhiyuan_2007/article/details/71238216
http://nginx.org/en/docs/stream/ngx_stream_core_module.html
首先下载安装包和依赖包:
https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
http://nginx.org/download/nginx-1.14.0.tar.gz
安装其他需要的依赖包:
sudo yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
解压并安装pcre:
tar -zxf pcre-8.42.tar.gz
cd pcre-8.42
./configure --prefix=/usr/local/pcre
make
sudo make install
[taiji@localhost pcre-8.42]$ sudo /usr/local/pcre/bin/pcre-config --version
8.42
[taiji@localhost pcre-8.42]$
解压并安装nginx:
tar -zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=../pcre-8.42 --with-stream
make
sudo make install
配置防火墙:
sudo vim /etc/sysconfig/iptables
增加规则:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
重起iptables :
sudo service iptables restart
就可以访问nginx了
以下包含了 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
附上配置文件:
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
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"';
access_log logs/access.log main;
#开启高效传输模式。
sendfile on;
#防止网络阻塞
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#负载均衡
upstream my_pdi_pool {
server 192.168.7.156:8081;
server 192.168.7.157:8081;
}
upstream my_web_pool {
ip_hash;
server 192.168.7.156:8091;
server 192.168.7.157:8091;
}
#反向代理
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://my_web_pool;
}
}
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://my_pdi_pool;
}
}
#PDI
server {
listen 8081;
server_name localhost;
#charset koi8-r;
access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}