来源: 最后更新:2022-12-10 21:07:27
所需软件名称及版本:
pcre-8.02.tar.gz
nginx-0.7.58.tar.gz
Nginx_upstream_hash-0.3.1.tar.gz
1、安装pcre
tar -zxvf pcre-8.02.tar.gz
cd pcre-8.02/
./configure
make && make install
2、给nginx安装url_hash补丁
tar -zxvf nginx-0.7.58.tar.gz
tar -zxvf Nginx_upstream_hash-0.3.1.tar.gz
cd nginx-0.7.58/
patch -p0 < /var/tmp/loojoy/nginx_upstream_hash-0.3.1/nginx.patch
3、安装nginx
groupadd www
useradd www -g www
./configure --prefix=/usr/local/webserver/nginx
--user=www
--group=www
--add-module=/var/tmp/loojoy/nginx_upstream_hash-0.3.1
--with-http_ssl_module
--with-http_stub_status_module
4、检查nginx生成的配置文件是否正确
/usr/local/webserver/nginx/sbin/nginx -t
5、启动nginx
若nginx.conf检查通过,则启动nginx。
/usr/local/webserver/nginx/sbin/nginx
6、查看端口80
netstat -ant
7、通过浏览器访问:
http://your_nginx_server_ip/
若可以正常访问,则nginx安装成功。
8、修改nginx的配置文件如下:
-------------------url_hash转发方式nginx.conf--------------------
user www www
worker_processes 10
error_log logs/error.log
#error_log logs/error.log notice
#error_log logs/error.log info
#pid logs/nginx.pid
worker_rlimit_nofile 51200
events
{
use epoll
worker_connections 51200
}
http
{
include mime.types
default_type application/octet-stream
keepalive_timeout 120
tcp_nodelay on
upstream your.website.name{
server your.tomcat.server.ip1:8080
server your.tomcat.server.ip1:8080
hash $request_uri
}
server
{
listen 80
server_name your.website.name
location / {
proxy_pass http://your.website.name
proxy_set_header Host $host
proxy_set_header X-Real-IP $remote_addr
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for
}
log_format www_gjw_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
#access_log /data1/logs/www.log www_gjw_com
location /nginx_status {
stub_status on
access_log off
}
}
}
-------------------[E]url_hash转发方式nginx.conf[E]--------------------
9、添加nginx启动、关闭、重启脚本
-------------------[S]url_hash转发方式nginx启动、关闭脚本[S]--------------------
#!/bin/sh
CWD=`pwd`
case $1 in
start)
/usr/local/webserver/nginx/sbin/nginx
;
stop)
kill -2 `ps -ef|grep "/usr/local/webserver/nginx/sbin/nginx"|grep -v "grep"|awk '{print $2}' `
;
restart)
cd "$CMD"
$0 stop
$0 start
;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
-------------------[E]url_hash转发方式nginx启动、关闭脚本[E]--------------------
更改该文件权限
chmod u+x nginx.sh
启动 nginx ./nginx.sh start
重启 nginx ./nginx.sh restart
关闭 nginx ./nginx.sh stop
腾讯为什么告老干妈(腾讯跟老干妈什么情况)
突然确诊癌症中晚期,已转移!宁波男子无法接受:怎么可能!医生:发现一个,全家高危!
疑似皇马前主席之孙公然辱华,皇马却称“将致力于消除足球界种族歧视”?
韩军称朝鲜军人无意中越界 韩军称朝鲜军人无意中越界了吗
中纪委再打两“虎”!还有一“虎”被免职,一“虎”获刑十五年!
吉林市将举办世界锅包肉大赛,此前召开座谈会论证锅包肉起源
哪些爱爱姿势更容易怀孕 选择这些爱爱姿势帮助生儿生女
男性精子存活时间有多久 精子存活率低怎么办
医生算错怀孕周数怎么办 孕龄胎龄预产期原来是这样算的
备孕未准妈妈请注意 这里有份孕前自检表请签收
疑似皇马前主席之孙公然辱华,皇马却称“将致力于消除足球界种族歧视”?
中纪委再打两“虎”!还有一“虎”被免职,一“虎”获刑十五年!中纪委再打两“虎”!还有一“虎”被免职,一“虎”获刑十五年!,常委,
停经几天能测出怀孕 诊断怀孕的常用方法有哪些 “疯狂”的栀子花:最高每斤卖35元!犍为栀子花价飙涨数倍,迎上中式新茶饮风口 澳媒揭露西方媒体歪曲报道中国真相:“它们不会告诉不想让我们听到的消息” monster monster眼镜