centos中安装nginx配置

  • 下载nginx压缩包:nginx官网下载
  • 将下载的安装包上传到自己的服务器
# 解压:
tar -zxvf nginx-1.8.1.tar.gz

# 进入目录:
cd /home/root/nginx-1.8.1

# 执行安装:
./configure
make
make install

# 如果安装过程中有报错可能是你的服务器缺少yum依赖:
# 执行安装依赖:
yum install gcc build-essential
yum install gcc gcc-c++ autoconf automake
yum -y install pcre-devel
yum -y install openssl openssl-devel

##再次执行安装即可;

# 安装之后执行:
whereis nginx   # 查找安装路径
nginx: /usr/local/nginx

# nginx 启动路径
cd /usr/local/nginx/sbin

# nginx.conf文件目录:
cd /usr/local/nginx/conf/

# 指定配置文件启动
./nginx -c  /usr/local/nginx/conf/nginx.conf

# 默认配置文件启动
/usr/local/nginx/sbin/nginx

# 停止指令 cd /usr/local/nginx/sbin
./nginx -s stop

# 重启命令 cd /usr/local/nginx/sbin
./nginx -s reload

nginx安装之后直接修改配置文件 默认路径:

vi /usr/local/nginx/conf/nginx.conf
  • server {
    		listen 80;
    		server_name localhost;
    		
    		
    		# 打包好的dist目录文件,放置到这个目录下
    		#root /data/pig-ui/;
    		#root /var/dist/;      
    		location / {
    		root /opt/dist/;
    		index index.html index.htm;
    		 }	
    
    
    
    		location /apis/  {
    		   proxy_pass http://localhost:9999/;
    		   #proxy_set_header Host $http_host;
    		   proxy_connect_timeout 15;
    		   proxy_send_timeout 15;
    		   proxy_read_timeout 15;
    		   proxy_set_header X-Real-IP $remote_addr;
    		   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    		}
    	}

    代理到其他服务器:

    location / {
               proxy_pass http://192.168.×××.×××:8080;
               proxy_connect_timeout 15;
               proxy_send_timeout 15;
               proxy_read_timeout 15;
               proxy_set_header Host $http_host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }

    重新加载即可:
  • ./nginx -s reload

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼大虾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值