Linux nginx安装 配置反向代理 配置上传限制

Linux nginx安装
一、解压
tar -zxvf nginx-1.9.9.tar.gz

[root@aubin local]# ls
bin games install lib64 mysql nginx-1.9.9.tar.gz share test
etc include lib libexec nginx-1.9.9 sbin src uppackage

**二、安装 nginx 依赖 **
[root@aubin local]# yum -y install gcc pcre-devel zlib-devel openssl openssl-deve
Complete!

[root@aubin local]# cd nginx-1.9.9
[root@aubin nginx-1.9.9]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src

三、配置
[root@aubin nginx-1.9.9]# ./configure --prefix=/usr/local/nginx
Configuration summary

  • using system PCRE library
  • OpenSSL library is not used
  • using builtin md5 code
  • sha1 library is not found
  • using system zlib library

[root@aubin nginx-1.9.9]# make

[root@aubin nginx-1.9.9]# make install

[root@aubin nginx-1.9.9]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src

四、测试是否安装成功
[root@aubin nginx-1.9.9]# cd …
[root@aubin local]# cd nginx
[root@aubin nginx]# ./sbin/nginx -t 测试是否安装成功
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@aubin nginx]# cd sbin
[root@aubin sbin]# ./nginx 启动成功

五、如果失败
ping ip未成功 解决 :
[root@aubin sbin]# ping 192.168.1.12
PING 192.168.1.12 (192.168.1.12) 56(84) bytes of data.
From 36.112.252.17 icmp_seq=39 Destination Net Unreachable

解决:
[root@aubin sbin]# systemctl start firewalld
[root@aubin sbin]# firewall-cmd --add-port=80/tcp --permanent
success
[root@aubin sbin]# systemctl restart firewalld
[root@aubin sbin]#

页面访问 http://192.168.78.128/ 显示 Welcome to nginx! 成功

目录位置:
在这里插入图片描述
进入安装目录中,
命令: cd /usr/local/nginx/sbin
启动,关闭,重启,命令:
./nginx 启动
./nginx -s stop 关闭
./nginx -s reload 重启

配置反向代理 也是修改 cd /usr/local/nginx/conf 下的 nginx.conf 文件
启动 也是修改 cd /usr/local/nginx/sbin 下的

nginx配置反向代理 配置上传限制

一、配置
例如测试 项目:域名 ,对应 本机或是 虚拟机的ip 192.168.78.128

TestF服务 http://xxx1.com.cn 项目一
Gitea服务 http://xxx2.com.cn 项目二

目前由于没有公网ip并且内部测试
在 本地测试 需要借助 本机的 hosts 文件
地址C:\Windows\System32\drivers\etc\
添加 192.168.78.128 http://xxx1.com.cn
192.168.78.128 http://xxx2.com.cn

浏览器输入 http://xxx1.com.cn 然后找到
本机的hosts文件 找到对应的192.168.78.128 访问这台电脑
本地环境没有公网ip时 本机模拟就得配置hosts文件

nginx.conf 文件 内容

user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#配置www.sina.com:80对应的服务器监听端口
server {
listen 80;
server_name http://xxx1.com.cn;
client_max_body_size 500M; //这里是上传限制配置
location / {
proxy_pass http://192.168.78.128:8080/;
}
}
#配置www.houhu.com:80对应的服务器监听端口
server {
listen 80;
server_name http://xxx2.com.cn;
client_max_body_size 500M; //这里是上传限制配置
location / {
proxy_pass http://192.168.78.128:8081/;
}
}
#这个没什么用 可以不写
server {
listen 80;
server_name localhost;
client_max_body_size 500M;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

补充:

nginx 502 Bad Gateway解决办法
当nginx配置了反向代理后 出现nginx 502 Bad Gateway解决办法 可能是tomcat挂掉了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值