linux系统安装nginx
准备工作
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel cd /usr/local/src/ 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 ./configure make && make install pcre-config --version
开始nginx的安装
cd /usr/local/src/
wget https://yourheart.live/upload/2024/03/1nu7tbltuchkqocruelmrgevbo.gz
tar zxvf 1nu7tbltuchkqocruelmrgevbo.gz
cd nginx-1.6.2
./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/local/webserver/nginx/sbin/nginx -v
/usr/sbin/groupadd www /usr/sbin/useradd -g www www
cd /usr/local/webserver/nginx/conf
下面就可以配置nginx.conf文件了
worker_processes 1; 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; #keepalive_timeout 0; keepalive_timeout 65; upstream tomcat_server_pool{ server 134.175.126.129:1009 weight=10; #server 134.175.126.129:1010 weight=10; #server 134.175.126.129:1011 weight=10; } server { listen 80; server_name localhost; location / { proxy_pass http://tomcat_server_pool; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
启动nginx
/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