安装nginx服务器
1 |
yum install nginx |
如果无法安装nginx看下面的方法,可以就直接跳到下方启动nginx
1 |
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm |
然后再次使用yum命令安装nginx库在使用第一条命令安装nginx
1 |
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.njupt.edu.cn * extras: mirrors.nju.edu.cn * updates: mirrors.nju.edu.cn Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 0:1.14.0-1.el6.ngx will be installed --> Processing Dependency: libpcre.so.0()(64bit) for package: nginx-1.14.0-1.el6.ngx.x86_64 --> Finished Dependency Resolution Error: Package: nginx-1.14.0-1.el6.ngx.x86_64 (nginx) Requires: libpcre.so.0()(64bit) You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest |
如果安装出现上面的情况有2种可能:
1.没有网络可以试着ping www.baidu.com,看有没有网没有就没法下载了。
2.缺少 epel-release
1 2 |
sudo yum install epel-release -y sudo yum install nginx -y |
在结尾出现Complete! Nginx在服务器上完成安装。
1 2 3 4 5 |
nginx -v #查看nginx版本 rpm -ql nginx #查看nginx的安装目录 nginx -t #测试nginx的配置 systemctl start nginx #启动nginx systemctl enable nginx #设置开机自动启动nginx |
如果防火墙在运行中,执行以下命令:
1 2 3 |
firewall-cmd --permanent --zone=public --add-service=http --permanent #放行http firewall-cmd --permanent --zone=public --add-service=https --permanent #放行https firewall-cmd --reload #使配置生效 |
接下来在浏览器输入服务器ip访问就可以了

安装PHP
一. 更新yum安装包
1 2 3 4 5 6 7 |
CentOS 7.x rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm CentOS 6.x rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm CentOS 5.x rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm |
二. yum安装PHP及组件
1 |
yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64 php70w-fpm -y |
查看php已安装版本
1 |
php -v |
创建phpinfo文件查看php状态
1 2 3 |
<php? phpinfo(); ?/> |
申请https证书
本篇不再重复,详情请见:xxxxxx 文章
修改nginx.conf配置文件
1 2 3 |
cd /etc/nginx cp -p nginx.conf nginx.conf.bak vim nginx.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
server { listen 80; listen 443 ssl http2; ssl_certificate /usr/local/nginx/conf/ssl/google.0513c.site.crt;#按照自己路径更改 ssl_certificate_key /usr/local/nginx/conf/ssl/google.0513c.site.key;#按照自己路径更改 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_session_timeout 10m; ssl_prefer_server_ciphers on; ssl_ciphers CHACHA20:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS; ssl_session_cache builtin:1000 shared:SSL:10m; proxy_redirect off; proxy_pass https://www.google.co.jp/; proxy_redirect http://www.google.com/ /; proxy_cookie_domain google.com guance.com; proxy_set_header Accept-Encoding ""; proxy_set_header User-Agent $http_user_agent; proxy_set_header Accept-Language "zh-CN"; resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 5s; location / { } } server { listen 80; server_name google.0513c.site; #设置成自己绑定的主机头 rewrite ^(.*)$ https://$host$1 permanent; #访问http跳转至https } |
测试nginx配置文件正确
1 |
nginx -t |
正确的话重启服务
1 |
systemctl resatrt nginx |