配置http和https

修改http配置文件并授权访问


[root@150 ~]# dnf -y install httpd
[root@150 ~]# ss -antl
State             Recv-Q            Send-Q                         Local Address:Port                         Peer Address:Port            Process
LISTEN            0                 128                                  0.0.0.0:111                               0.0.0.0:*
LISTEN            0                 128                                  0.0.0.0:22                                0.0.0.0:*
LISTEN            0                 128                                     [::]:111                                  [::]:*
LISTEN            0                 128                                        *:80                                      *:*
LISTEN            0                 128                                     [::]:22                                   [::]:*
[root@150 ~]#systemctl stop firewalld
[root@150 ~]# cd /var/www/html/

将斗地主压缩包上传到/var/www/html/中

[root@150 html]# ls
斗地主.zip
[root@150 html]# unzip 斗地主.zip
[root@150 html]# ls
'HTML5 canvas移动端斗地主小游戏'   斗地主.zip
[root@150 html]# rm -rf 斗地主.zip
[root@150 html]# mv 'HTML5 canvas移动端斗地主小游戏'/  doudizhu
[root@150 html]# ls
doudizhu
[root@150 html]#
[root@150 html]# cd doudizhu/
[root@150 doudizhu]# ls
DJDDZ.js  img  index.html  JControls.js  Prototype.js  ResourceData.js
[root@150 doudizhu]#

在网页中访问该游戏目录

访问成功后开始授权访问,在httpd配置文件中修改配置,只拒绝192.168.89.150访问,允许其他ip访问

[root@150 doudizhu]# cd
[root@150 ~]# cd /etc/httpd/
[root@150 httpd]# ls
conf  conf.d  conf.modules.d  logs  modules  run  state
[root@150 httpd]# cd conf
[root@150 conf]# ls
httpd.conf  magic
[root@150 conf]# vim httpd.conf
 98 ServerName www.example.com:80

162 <Directory  "/var/www/html/doudizhu">
163     <RequireAll>
164         Require not ip 192.168.89.150
165         Require all granted
166     </RequireAll>
167 </Directory>
168
[root@150 conf]# httpd -t
Syntax OK
[root@150 conf]#
[root@150 conf]# systemctl restart httpd

在物理机中能够访问到

只允许192.168.89.150访问,其他全部拒绝

[root@150 conf]# vim httpd.conf
162 <Directory  "/var/www/html/doudizhu">
163     <RequireAll>
164         Require  ip 192.168.89.150
165     </RequireAll>
166 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置Nginx同时支持HTTPHTTPS,您需要进行如下步骤: 1. 安装Nginx: 在Ubuntu中,可以使用以下命令安装Nginx: ``` sudo apt-get update sudo apt-get install nginx ``` 2. 配置HTTP: 默认情况下,Nginx已经配置为监听端口80,并将HTTP流量转发到正确的位置。您可以使用文本编辑器打开`/etc/nginx/sites-available/default`文件进行进一步配置: ``` sudo nano /etc/nginx/sites-available/default ``` 在`server`块中添以下内容,以配置HTTP: ``` server { listen 80; server_name your_domain.com; location / { # 配置HTTP的处理逻辑 } } ``` 将`your_domain.com`替换为您的域名,然后保存并关闭文件。 3. 配置HTTPS: 要启用HTTPS,您需要获得一个有效的SSL证书。您可以购买商业证书,或使用免费的Let's Encrypt证书。安装并配置certbot工具来获取Let's Encrypt证书: ``` sudo apt-get install certbot sudo certbot certonly --nginx -d your_domain.com ``` `your_domain.com`替换为您的域名。根据提示完成证书申请过程。 4. 更新Nginx配置以支持HTTPS: 使用文本编辑器打开`/etc/nginx/sites-available/default`文件,并添以下内容以配置HTTPS: ``` server { listen 443 ssl; server_name your_domain.com; ssl_certificate /etc/letsencrypt/live/your_domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your_domain.com/privkey.pem; location / { # 配置HTTPS的处理逻辑 } } ``` 将`your_domain.com`替换为您的域名,并确保`ssl_certificate`和`ssl_certificate_key`路径正确指向您的证书文件。保存并关闭文件。 5. 重启Nginx: 完成配置后,使用以下命令重启Nginx以使更改生效: ``` sudo service nginx restart ``` 现在,您的Nginx服务器应该同时支持HTTPHTTPS。您可以根据需要在每个`location`块中定义适当的处理逻辑来区分HTTPHTTPS请求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值