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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM