Nginx在 Linux 环境中的服务搭建

版权声明:尊重博主原创文章,转载请注明出处。如有不妥之处,望各位指正。联系方式:[email protected] https://blog.csdn.net/Supreme_Sir/article/details/80466599

PS:请在 Linux 中以安装并配置完成 Tomcat 后进行如下步骤

1、先将 nginx 上传到 linux
2、解压 nginx
3、编译 nginx

  • 安装依赖包

    yum install gcc-c++
    yum install -y pcre pcre-devel
    yum install -y zlib zlib-devel
    yum install -y openssl openssl-devel

  • 先进入 nginx 的目录执行编译

    ./configure

4、执行安装 nginx

make  
make install  

5、启动 nginx

进入 nginx 目录下并执行

./nginx   

6、将端口号 80 放行

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT  

将该设置添加到防火墙的规则中

/etc/rc.d/init.d/iptables save  

7、修改 conf 目录下的 nginx.conf 文件

代码如下:

#gzip  on;

upstream server_xxx{
	#通过 weight 属性可设置被代理服务器权重,值越大权重越高,越容易被访问(可省略)
	server 127.0.0.1:8080 weight=1;
	server 127.0.0.1:8081 weight=2;
}

server {
	listen       80;
	server_name  localhost;
	
	#charset koi8-r;
	
	#access_log  logs/host.access.log  main;
	
	location / {
	root   html;
	index  index.html index.htm;
	#代理单个服务器
	#proxy_pass http://localhost:8080;
	#代理集群
	proxy_pass http://server_xxx;
}

#error_page  404              /404.html;  

8、重新加载 nginx 配置文件

./nginx -s reload  

PS: 内容整理自网络

猜你喜欢

转载自blog.csdn.net/Supreme_Sir/article/details/80466599