安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel下载nginx
//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz安装nginx
//进入nginx目录
cd nginx-1.13.7
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install配置防火墙
Failed to restart iptables.service: Unit not found.
解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory.
firewall-cmd --zone=public --add-port=80/tcp --permanent
#(--permanent永久生效,没有此参数重启后失效)重新载入
firewall-cmd --reload
查看
firewall-cmd --zone=public --query-port=80/tcp
删除
firewall-cmd --zone=public --remove-port=80/tcp --permanentNginx虚拟域名配置
//编辑nginx.conf
sudo vim /usr/local/nginx/conf/nginx.conf
//增加行
include vhost/*.conf
//保存退出
//在/usr/local/nginx/conf目录新建vhost文件夹
mkdir vhost
//创建每个域名的配置
sudo vim jimisun.com.conf
//节点中增加入响应的配置 端口转发 或者访问文件系统Nginx启动
//进入nginx安装目录
cd sbin
sudo ./nginx//启动命令
./nginx
//停止命令
./nginx -s stop
或者 : nginx -s quit
//重启命令
./nginx -s reloadLINUX安装NGINX
nginx禁止使用ip地址直接访问
打开文件/etc/nginx/nginx.conf
将原server中的两个default_server去掉
换成
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 444;
} linux_nginx环境配置
linux_nginx反向代理
linux nginx配置新项目加域名
server{
server_name default sofun.net.cn iwstf.com snapshot.wiki;
rewrite ^(.*) http://lizhenqiu.com$1 permanent;
}
安装nginx
输入命令./nginx -t
看到如下显示nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确
在启动命令-c前加-t
Linux下ftp服务可以通过搭建vsftpd服务来实现
执行 systemctl start vsftpd.service 启动vsftp服务,然后可以通过命令: systemctl status vsftpd.service 查看ftp服务的运行状态
sftp和ftp区别在于:文件的安全性
FTP是一种文件传输协议,一般是为了方便数据共享的。包括一个FTP服务器和多个FTP客户端。FTP客户端通过FTP协议在服务器上下载资源。
SFTP协议是在FTP的基础上对数据进行加密,使得传输的数据相对来说更安全。但是这种安全是以牺牲效率为代价的。
SFTP的传输效率比FTP要低。
https服务器配置、nginx配置、系统的443端口检查和开启
查看了所运行的端口
>
(如果发现端口没有443),说明该端口防火墙没有配置到,所以也不能进行代理的操作;及没有找到下面这个
解决办法:
进入防火墙配置文件看看了
vim /etc/sysconfig/iptables
// 看看有没有443的文件,没有的话在改文件中添加下面这行
>-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
再次注意,
>-A INPUT -j REJECT –reject-with icmp-host-prohibited
添加的新的那句需要在这句的前面,否则443端口也有问题
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面
原因是这条规则的作用是拒绝所有-j REJECT 在iptables帮助文档里面有一下说明This is used to send back an error packet in response to the matched packet
就是表明拒绝你,并返回一个错误连接信息。请求没到nginx那,肯定没有状态码返回,同时你的浏览器返回的只能是无法连接。
被netstat -anp 出来的内容欺骗了,规则是添加了,但是没起效果。
如果返回404,403等等,那说明是nginx的配置等因素;
/usr/local/nginx/sbin/nginx -s reload 时报invalid PID number报错
Nginx启动SSL功能,并进行功能优化
1.1 Nginx如果未开启SSL模块,配置Https时提示错误
原因也很简单,nginx缺少http_ssl_module模块,编译安装的时候带上--with-http_ssl_module配置就行了,但是现在的情况是我的nginx已经安装过了,怎么添加模块,其实也很简单,往下看: 做个说明:我的nginx的安装目录是/usr/local/nginx这个目录,我的源码包在/usr/local/src/nginx-1.6.2目录
1.2 Nginx开启SSL模块
切换到源码包:
查看nginx原有的模块
在configure arguments:后面显示的原有的configure参数如下:
那么我们的新配置信息就应该这样写:
运行上面的命令即可,等配置完
配置完成后,运行命令
这里不要进行make install,否则就是覆盖安装
然后备份原有已安装好的nginx
然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
然后启动nginx,仍可以通过命令查看是否已经加入成功
Nginx 配置Http和Https共存
把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
Nginx 配置SSL安全证书重启避免输入密码
可以用私钥来做这件事。生成一个解密的key文件,替代原来key文件。
Nginx SSL性能调优
Nginx 配置Http跳转Https
解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory.
CentOS7中执行
service iptables start/stop
会报错Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.
在CentOS 7或RHEL 7或Fedora中防火墙由firewalld来管理,
如果要添加范围例外端口 如 1000-2000
语法命令如下:启用区域端口和协议组合
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
此举将启用端口和协议的组合。端口可以是一个单独的端口 <port> 或者是一个端口范围 <port>-<port> 。协议可以是 tcp 或 udp。
实际命令如下:
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone=public --query-port=80/tcp
删除
firewall-cmd --zone=public --remove-port=80/tcp --permanent
当然你可以还原传统的管理方式。
执行一下命令:
systemctl stop firewalld
systemctl mask firewalld
并且安装iptables-services:
yum install iptables-services
设置开机启动:
systemctl enable iptables
systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables
保存设置:
service iptables save
OK,再试一下应该就好使了
开放某个端口 在/etc/sysconfig/iptables里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
输入 service iptables restart
Redirecting to /bin/systemctl restart iptables.service
Failed to restart iptables.service: Unit not found.
被完美解决!!!
“ 查看 firewall-cmd --zone= public --query-port=80/tcp ” 这个语句输入后报错 “ usage: see firewall-cmd man page firewall-cmd: error: unrecognized arguments: public ” 将语句修改为 “ firewall-cmd --query-port=80/tcp ” 后可以使用
Failed to start iptables.service: Unit not found. 这个错误也可以解决...
linux解决nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
解决:查看端口
找到80端口的PID