CentOS 7.6 安装 nginx,配置端口访问网站,切换root目录
20190329 CentOS 7.6 安装 nginx,配置端口访问网站
1、查询一下 nginx
yum search nginx已加载插件:fastestmirrorRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fastDetermining fastest mirrors* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.comepel 12744/12744......** 如果已经有旧版本,可以重新卸载安装
2、安装 nginx
sudo yum install -y nginx启动并设置为开机启动
基本指令:sudo systemctl start nginx.servicesudo systemctl enable nginx.servicesudo systemctl status nginx.servicesudo systemctl restart nginx.service查看版本,确认启动nginx -vnginx version: nginx/1.12.2
ps -ef |grep nginx测试网站配置sudo nginx -tcurl 127.0.0.1
3、配置 8080 端口访问的网站
参考
https://m.linuxidc.com/Linux/2019-02/156789.htm
https://blog.csdn.net/yongzhang52545/article/details/51282914
1. 检查 nginx 配置文件sudo vim /etc/nginx/nginx.conf内容摘要如下:server {listen 80 default_server;listen [::]:80 default_server;server_name _;root /usr/share/nginx/html;....# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;配置网站模块放在 /etc/nginx/conf.d/*.conf 下
2. 新建一个网站 : chuangke.conf cd /etc/nginx/conf.dsudo vim chuangke.conf加入以下内容server {listen 8080;server_name 127.0.0.1;root /usr/share/nginx/chuangke;# root /var/www/chuangke;index index.html;location / {}}测试一下配置sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful重启 nginxsudo systemctl restart nginx测试网站
curl 127.0.0.1:8080
使用 root /var/www/chuangke 总是 403 错误?!<html><head><title>403 Forbidden</title></head><body bgcolor="white"><center><h1>403 Forbidden</h1></center><hr><center>nginx/1.12.2</center></body></html>
4、 开放 8080 端口
1. 查看防火墙状态sudo systemctl status firewalldsudo firewall-cmd --staterunning
2. 防火墙基本命令# 开启service firewalld start# 重启service firewalld restart# 关闭sudo service firewalld stop# 查看防火墙规则sudo firewall-cmd --list-all sudo firewall-cmd --state
3. 开启 8080 端口sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent重启防火墙sudo systemctl restart firewalld.servicesudo firewall-cmd --reload4. 不知道为什么,就把自己关在外面了 ssh 连接不上去了!sudo firewall-cmd --list-all public (active)target: defaulticmp-block-inversion: nointerfaces: enp0s3sources: services: ssh dhcpv6-clientports: protocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules: ** 可以看到,ports 一个都没有! ** 干脆重新增加端口的时候,先加上 20,22 端口sudo firewall-cmd --zone=public --add-port=80/tcp --permanentsudo firewall-cmd --zone=public --add-port=22/tcp --permanentsudo firewall-cmd --zone=public --add-port=21/tcp --permanentsudo firewall-cmd --zone=public --add-port=20/tcp --permanentsudo firewall-cmd --zone=public --add-port=8080/tcp --permanentsudo firewall-cmd --zone=public --add-port=4433/tcp --permanent重启防火墙sudo systemctl restart firewalld.service
重新查看防火墙规则sudo firewall-cmd --list-all public (active)target: defaulticmp-block-inversion: nointerfaces: enp0s3sources: services: ssh dhcpv6-clientports: 80/tcp 22/tcp 21/tcp 20/tcp 8080/tcp 4433/tcpprotocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules:
** 现在可以安全的退出、重新 ssh 了!
5、再增加一个其他端口 (例如:4433)发生错误
1. 测试:将以上 chuangke.conf 的端口改成 4433后sudo systemctl restart nginx返回错误!Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.2. 测试 nginx 配置是 OK!sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful3. 查看错误信息sudo systemctl status nginx.service......3月 29 15:07:26 centos7-71 nginx[18289]: nginx: [emerg] bind() to 0.0.0.0:4433 failed (13: Permission denied)......3月 29 15:07:26 centos7-71 systemd[1]: Unit nginx.service entered failed state.3月 29 15:07:26 centos7-71 systemd[1]: nginx.service failed.
** 4433 端口不允许!
6、semanage 解决 http 端口访问配置(Selinux)
参考
https://blog.csdn.net/runsnail2018/article/details/81185138
https://zhb1208.iteye.com/blog/1432957
1. 直接安装 semanage 会提示:没有 semanagesudo yum updatesudo yum install semanage 已加载插件:fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com没有可用软件包 semanage。错误:无须任何处理2. 按照参考文档,执行一下设置和安装命令1). yum provides /usr/sbin/semanage2). yum -y install policycoreutils-python3). 现在就可以执行 semanage 命令了
3. 查看 http 可以访问的端口sudo semanage port -l | grep http_port_thttp_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988** 果然没有发现 4433 端口!
4. 增加 4433 到 http 访问端口sudo semanage port -a -t http_port_t -p tcp 4433
5. 再来看看 http 端口
sudo semanage port -l | grep http_port_thttp_port_t tcp 4433, 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988
** 现在可以访问 4433 了sudo systemctl restart nginxsudo systemctl status nginx.serviceOK!
一直没有搞明白 SELinux 干么用的!现在有点儿明白了!
不是简单从防火墙开放一个端口就可以了
还要配置 特定服务(这次是 HTTP)可以使用哪些端口
6、切换root目录一直 403 错误
参考
https://blog.csdn.net/a690392431/article/details/85914076
** 这个博客应该是正确的!但是,我照着操作了,还是不行!
实在没有办法了!
只好先关闭 SELinux !以后再学习!sudo vim /etc/selinux/config# by wzh 20190329 disable SELINUXSELINUX=disabled# SELINUX=enforcing重启才能生效!查看 SELinux
sestatusSELinux status: disabled
CentOS 7.6 安装 nginx,配置端口访问网站,切换root目录相关推荐
- Centos 7离线安装Nginx 配置负载均衡集群
场景 项目中有三台应用服务器,系统为Centos 7 ,应用地址分别为: 192.168.198.229:8080 192.168.198.230:8080 192.168.198.231:8080 ...
- linux nginx 配置端口访问,Linux入门教程:ubuntu 16.04配置nginx服务器实现一个IP一个端口多个站点,ubuntunginxNginx 使用异步...
Linux入门教程:ubuntu 16.04配置nginx服务器实现一个IP一个端口多个站点,ubuntunginxNginx 使用异步 特点: Nginx 可以部署在网络上使用 FastCGI,脚本 ...
- nginx 设置端口访问网站
2019独角兽企业重金招聘Python工程师标准>>> server { listen 8004; ...
- 如何在 CentOS 7 上安装 Nginx
本文首发:开发指南:如何在 CentOS 7 上安装 Nginx Nginx 读作 engine x, 是一个免费的.开源的.高性能的 HTTP 和反向代理服务,主要负责负载一些访问量比较大的站点. ...
- centos 7 在线安装nginx 查看gcc,pcre,zlib,openssl 等依赖是否安装
之前整理过centos 7 离线安装nginx的步骤 在线安装相对操作就简易多了 查看安装nginx需要的依赖是否已安装 没安装yum指令在线安装即可 我使用的是centos7.6版本 安装的ngin ...
- centOS 7 离线安装 nginx 1.21
NGINX 离线安装 centOS 7 离线安装 nginx 1.21.6 准备环境 1.离线 centOS 7 2.nginx 安装文件 (nginx-***.tar.gz 已放到下面的链接中,请自 ...
- 如何在CentOS 7上安装和配置MySQL Cluster
翻译&转载:https://www.howtoforge.com/tutorial/how-to-install-and-configure-mysql-cluster-on-centos-7 ...
- CentOS下MySQL安装后配置和设置
CentOS下MySQL安装后配置和设置: 1:安装完成路径: 1.数据库目录/var/lib/mysql/2.配置文件/usr/share/mysql(mysql.server命令及配置文件)3.启 ...
- 在CentOS 8上安装与配置Apache虚拟主机
实验环境 操作系统:Centos 8 web应用:apache 内网IP:192.168.3.21 shell执行:root 以root或具有sudo权限的用户身份登录执行如下操作. 主配置文件路径: ...
- Centos 7编译安装Nginx
Centos 7编译安装Nginx 第一步:防火墙开启80端口或关闭防火墙 第二步:下载Nginx的压缩包 第三步:安装Nginx所需要的环境 第四步:解压Nginx的压缩包 第五步:配置Nginx ...
最新文章
- Java - Java集合中的安全失败Fail Safe机制 (CopyOnWriteArrayList)
- 产品经理面试中如何攻克有关用户体验的问题?
- android 数据存储----android短信发送器之文件的读写(手机+SD卡)
- 这道笔试题竟然运行不出错
- 转义字符简析及注意事项
- Kubernetes 环境搭建 - MacOS
- 504 Gateway Time-out 错误处理记录
- java基本操作-2
- 必不可少需要掌握的嵌入式知识(2) -- 经典数据结构总结之 (链表,队列)
- 工业循环冷却水处理设计规范_循环冷却水系统及其水处理
- 安卓按键:紫猫老师的正则教程
- linux 解压 7z 分卷压缩文件,linux分卷压缩与解压缩
- 从数据结构的角度来看Mysql为什么使用B+树
- 超时空智慧办公白皮书(2023)
- 肝肠轴——看不见的Crosstalk
- ABAP BTE增强举例
- 牛人整理的一些查询国内外文献资料的实用网站,专业啊,吐血推荐!
- 2020年度开发者工具Top 100名单!
- Web大学生网页作业成品:个人博客主页 (纯HTML+CSS代码)
- conda删除虚拟环境
热门文章
- H5(仅仅是个地址)
- WCP源码分析 与SpringMVC学习资料
- 【BZOJ5082】弗拉格 矩阵乘法
- ssh整合(spring + struts2 + hibernate)xml版
- Python图片与其矩阵数据互相转换
- 解决 Error: Table './db_name/table_name' is marked as crashed and last (automatic?) repair
- 一道经典面试题的不同解法
- Windows mobile美化之-短信界面美化修改~
- 开源的读取Excel文件组件-ExcelDataReader
- php 二位数组排序