nginx部署

官网下载安装包

wget https://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.2-1.el7.ngx.x86_64.rpm

安装

yum -i -c nginx-1.20.2-1.el7.ngx.x86_64.rpm

修改配置文件

vim /etc/nginx/nginx.conf

# 在http{}中,server{}之上加入如下内容
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_headers_hash_max_size 1024;
proxy_headers_hash_bucket_size  128;

server {
   listen 80;
   server_name ip地址;

   location / {
       root /usr/local/blog/front/build;
       index index.html index.htm;
       try_files $uri $uri/ /index.html;
    }

    location /admin {
        root /usr/local/blog/;
        index index.html index.htm;
        try_files $uri $uri/ /admin/index.html;
    } # 配置后端访问地址

    location ~ .*\.(git|jpg|pdf|jepg|png)$ {
        root /home/plumemo/blog/;
    }

    location ^~ /api/blog {
        index  index.html index.htm index.php;
        index  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        index  proxy_set_header Host $host;
        index  proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:8086/api/plumemo-service; #后端服务器,配置upstream即可
    }
}

nginx 常用操作

#启动nginx
systemctl start nginx
#停止 nginx
systemctl stop nginx
#重启 nginx
systemctl restart nginx
#重新加载配置
systemctl reload nginx
#设置开机启动
systemctl enable nginx
#关闭开机启动设置
systemctl disable nginx
#查看版本
nginx -V
#查看进程
ps -ef | grep nginx 
#查看端口
netstat -nptl 

nginx常用目录

|目录|说明|
|-|-|-|
| /etc/nginx/ | 所有相关配置文件目录 |
| /etc/nginx/nginx.conf | nginx主配置文件 |
| /etc/nginx/conf.d/ | 独立的nginx服务配置文件目录 |
| /var/log/nginx/ | nginx日志文件目录 |
| /var/log/nginx/access.log | 访问日志(IP/浏览器信息/处理时间/请求URL) |
| /var/log/nginx/error.log | 错误日志(服务器和请求处理中的错误信息) |
| /usr/share/nginx/html | 默认的站点位置,可以根据实际情况进行设置调整 |
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值