linux服务器安装主从nginx

linux服务器安装主从nginx,第1张

linux服务器安装主从nginx 1. 相关下载

在 /usr/local/software 目录下,下载nginx的tar包:

wget http://nginx.org/download/nginx-1.9.9.tar.gz

安装要用到的依赖工具:

 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2. 解压安装主nginx

将tar包解压到指定路径 /usr/local/ ⇒ /usr/local/nginx-1.9.9

tar -zxvf nginx-1.9.9.tar.gz -C /usr/local/

重命名:

mv nginx-1.9.9 nginx

参数配置,并安装ssl模块:

cd nginx

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --with-http_ssl_module

编译:

make && make install
3. 安装从nginx

可以先建立所需目录:

mkdir /usr/local/nginx_p1

然后在主nginx目录下(/usr/local/nginx)对从nginx进行配置:

./configure --prefix=/usr/local/nginx_p1 --conf-path=/usr/local/nginx_p1/nginx.conf --with-http_ssl_module

编译:

make && make install

此时从nginx_p1目录下就有了相应文件

4. 端口配置

主nginx,其目录下有nginx.conf文件可以直接修改,不必去默认的conf目录下修改nginx.conf,使其监听80端口,有base路由的,直接转到9444端口:

	 server {
	        listen       80;
	        server_name  localhost;
	        
	        location    ^~ /base/  {
	            proxy_pass http://localhost:9444/;
	         }
	
	        location / {
	            root   html;
	            index  index.html index.htm;
	        }
	        ...
	}

从nginx,同样直接修改nginx.conf,使其监听9444端口,访问从nginx的html目录下文件:

	server {
	    listen       9444;
	    server_name  localhost;
	    
	    location / {
	        root   html;
	        index  index.html index.htm;
	    }
		...
	}

5. 启动

主,进入/usr/local/nginx/sbin目录下,指定启动所需的配置文件:

./nginx -c /usr/local/nginx/nginx.conf

从,同上:

./nginx -c /usr/local/nginx_p1/nginx.conf

此时只需访问 http://121.xxx.xxx.x/base/test.html 就能访问到从nginx的文件

6. 问题

(1) nginx的error日志 报错:

signal process started

网上说,主要是因为配置问题,可以考虑查线程,k掉,然后重启主从nginx:

ps -ef | grep nginx
root     20157     1  0 17:09 ?        00:00:00 nginx: master process ./nginx -c /usr/local/nginx/nginx.conf
nobody   20158 20157  0 17:09 ?        00:00:00 nginx: worker process
root     21483   301  0 17:11 pts/0    00:00:00 grep --color=auto nginx

pkill -9 nginx

./nginx -s reload /usr/local/nginx/nginx.conf
./nginx -s reload /usr/local/nginx_p1/nginx.conf

当然,我还是没解决这问题,访问地址一直请求不到,浏览器一直转圈,而且nginx日志没有反应。推测是端口没开,去阿里云查了下,80确实没问题,一直默认开着呢…我又把nginx配置改成81,成功…不信邪,我把原来的阿里云80端口开放配置删了,又重新添加了一个80,成功

(2) 用 ./configure 命令时,如果不加后缀,可能出现编译复制错误,大概是,nginx会从默认的路径进行文件的打包复制。具体问题具体分析了

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5681148.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存