Liunx软件安装之Nginx

安装 Nginx

  1. 添加 Nginx 到 YUM 源
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2)yum 安装

yum install nginx
  1. 启动Nginx
sudo systemctl start nginx.service

出现上图,表示安装成功。

设置开机自启动

除了之前设置开机脚本外,我们也可以通过 systemctl enable 命令 来实现开机自启动服务。

systemctl enable nginx.service  # 设置开机自启动
systemctl disable nginx.service	# 关闭开机自启动

相关配置文件路径

网站文件存放默认目录

/usr/share/nginx/html

网站默认站点配置

/etc/nginx/conf.d/default.conf

自定义Nginx站点配置文件存放目录

/etc/nginx/conf.d/

Nginx全局配置

/etc/nginx/nginx.conf

简单反向代理配置

我们这边将 nginx 默认页面转为 tomcat 默认项目的页面即:输入 http://localhost 显示 http://localhost:8080 页面内容

  1. 编辑 default.conf 文件
vim /etc/nginx/conf.d/default.conf 

将 location 标签编辑成如下内容:

# location / {
#    root   /usr/share/nginx/html;
#    index  index.html index.htm;
# }
 location / {
     proxy_pass http://localhost:8080;
     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;
 }

2)重启 nginx 服务,并刷新页面

systemctl restart nginx

可以看到已经将默认的网页转到 tomcat 默认项目上了

posted @ 2019-08-23 14:46  MarkLogZhu  阅读(203)  评论(0编辑  收藏  举报