linux搭建网站

CentOS

 1.安装

yum -y install nginx

*或者安装指定版本,版本网址:http://nginx.org/packages/centos/7/x86_64/RPMS/

rpm -ivh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.3-1.el7.ngx.x86_64.rpm
#安装rpm:sudo apt-get install rpm

配置文件

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

其他步骤参考下面debian的


 

debian

1.安装nginx

apt-get install nginx

设置开机启动:

systemctl enable nginx

2.上传网页文件

默认网页地址(可在配置文件中查看 /etc/nginx/sites-enabled/default):/var/www/html

将网站文件上传到目录

可使用 vsftpd

zip解压命令

unzip ***.zip

3.配置https

1)申请ssl证书(本人推荐阿里云直接生成,可跳过此步骤)

安装EPEL:

yum -y install epel-release

安装certbot用于签发SSL证书:

yum -y install certbot

申请SSL证书:

certbot certonly --standalone -d example.com

这里的example.com替换成你的域名

如果申请成功,证书和私钥路径如下:

/etc/letsencrypt/live/example.com/fullchain.pem

/etc/letsencrypt/live/example.com/privkey.pem

2)编辑配置文件:(Debian 9 VIM 使用鼠标右键复制

vi /etc/nginx/sites-enabled/default

添加:

        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        ssl_certificate    /etc/nginx/ssl_certs/***.pem;
        ssl_certificate_key    /etc/nginx/ssl_certs/***.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        error_page 497  https://$host$request_uri;   

http 跳转 https :

if ($scheme = http ) {return 301 https://$host$request_uri;}

使用301跳转比rewrite性能更高,原因在于rewrite使用正则表达式

完整配置文件示例:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        
        # SSL configuration
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        ssl_certificate    /etc/nginx/ssl_certs/jingdesign.top.pem;
        ssl_certificate_key    /etc/nginx/ssl_certs/jingdesign.top.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        error_page 497  https://$host$request_uri;

        root /var/www/html;
        server_name $host$;
        
        # https jump
        if ($scheme = http ) {return 301 https://$host$request_uri;}

        location / {
                # Add index.php to the list if you are using PHP
                index index.html index.htm index.nginx-debian.html;
        }
}

重启 nginx:

systemctl restart nginx

 

 防火墙关闭:

systemctl status firewalld查看当前防火墙状态。 systemctl stop firewalld关闭当前防火墙。 systemctl disable firewalld开机防火墙不启动。


https://baijiahao.baidu.com/s?id=1650170269926650594&wfr=spider&for=pc

https://www.jianshu.com/p/7419a027290d

https://www.jianshu.com/p/55888902d8bb

https://blog.csdn.net/chunyufeiyun/article/details/81079743

https://www.cnblogs.com/mafeng/p/8299289.html

https://blog.csdn.net/weixin_34270606/article/details/89730301

https://zq.zhaopin.com/answer/6451349/

posted @ 2020-04-04 00:36  冬音  阅读(1695)  评论(0编辑  收藏  举报