线上静态的前端、nginx环境基础、基于域名的虚拟主机、基于ip的访问、部署nfs

一、环境基础:

1.查看文件(不要注释及空行)

[root@17dns ~]# grep -Ev "#|^$" /usr/local/nginx/conf/nginx.conf

2.备份源文件:

[root@17dns ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

3.重定向:

[root@17dns ~]# grep -Ev "#|^$" /usr/local/nginx/conf/nginx.conf.bak >/usr/local/nginx/conf/nginx.conf

二、基于域名的虚拟主机

1.改文件配置,启服务

[root@17dns ~]# vim /usr/local/nginx/conf/nginx.conf

 [root@17dns ~]# /usr/local/nginx/sbin/nginx

2.创建项目,用于部署在nginx中发布到网络

[root@17dns ~]# mkdir /mmm
[root@17dns ~]# echo "hello world" >/mmm/index.html
[root@17dns ~]# cat /mmm/index.html 
hello world
[root@17dns ~]# 

3.将/mmm目录中资源文件发布

[root@17dns ~]# vim /usr/local/nginx/conf/nginx.conf

4.主机劫持ip

[root@17dns ~]# vim /etc/hosts

5.测试:

[root@17dns ~]# curl www.yulan.com
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

三、基于ip 访问

1.将配置的server文件模块保存到新的文件

[root@17dns ~]# sed -n '12,19p' /usr/local/nginx/conf/nginx.conf
    server{
        listen    80;
        server_name    www.yulan.com;
        root    /mmm;
        location / {
            index        index.html;
        }
    }
[root@17dns ~]# mkdir /usr/local/nginx/conf.d
[root@17dns ~]# sed -n '12,19p' /usr/local/nginx/conf/nginx.conf > /usr/local/nginx/conf.d/mm.conf
[root@17dns ~]# cat /usr/local/nginx/conf.d/mm.conf 
    server{
        listen    80;
        server_name    www.yulan.com;
        root    /mmm;
        location / {
            index        index.html;
        }
    }
[root@17dns ~]# sed -i '12,19d' /usr/local/nginx/conf/nginx.conf
[root@17dns ~]# cat /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;


    server {
        listen       80;
        server_name  localhost;
    root    html;
        location / {
            root   html;
            index  index.html index.htm;
        }
        location /status {
            stub_status on;
            access_log off;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
[root@17dns ~]# 

2.重启,真机访问

[root@17dns ~]# /usr/local/nginx/sbin/nginx -s reload

http//www.yulan.com

3.修改配置文件:

[root@17dns ~]# vim /usr/local/nginx/conf/nginx.conf

重启: /usr/local/nginx/sbin/nginx -s reload

四、上线一个静态的前端系统

1.安装nodejs  npm 

[root@17dns ~]# yum -y install nodejs

[root@17dns ~]# node -v

[root@17dns ~]# yum -y install npm

[root@17dns ~]# npm -v
8.19.4

2.配置npm包管理器

npm config set registry https://registry.npmmirror.com

[root@17dns ~]# npm install @vue/cli

3.查看版本

[root@17dns ~]# /root/node_modules/.bin/vue -V
@vue/cli 5.0.8

4.创建vue项目

[root@17dns ~]# /root/node_modules/.bin/vue create elema_web

[root@17dns ~]# cd elema_web
[root@17dns elema_web]# npm run serve

真机访问:

5.安装samba:

[root@17dns elema_web]# yum -y install samba

6.配置文件

[root@17dns elema_web]# vim /etc/samba/smb.conf

7.创建用户

[root@17dns elema_web]# useradd vueediter
[root@17dns elema_web]# smbpasswd -a vueediter
New SMB password:
Retype new SMB password:
Added user vueediter.
[root@17dns elema_web]# 

8.为该用户在文件夹中添加读写权限

[root@17dns elema_web]# setfacl -m u:vueediter:rwx /root/elema_web/

9.启服务

[root@17dns elema_web]# systemctl start nmb.service 
[root@17dns elema_web]# systemctl start smb.service

10.安装nfs

[root@17dns elema_web]# yum -y install nfs-utils.x86_64

五、部署nfs

1.安装

[root@13 ~]# yum -y install rpcbind

[root@13 ~]# yum -y install nfs-utils

2.更改配置文件

[root@13 ~]# vim /etc/exports

/static/img  *(rw,sync)

[root@13 ~]# mkdir -p /static/img

3.启服务

[root@13 ~]# systemctl start rpcbind 
[root@13 ~]# systemctl start nfs

4.回到主机17 挂载:

[root@17dns elema_web]# mount -t nfs 192.168.2.13:/static/img public/img/

5.真机上传资源到13主机/static/img目录下

6.在17主机查看:

[root@17dns elema_web]# ls public/img/

7.查找目录

[root@17dns elema_web]# cd /root
[root@17dns ~]# cd elema_web/
[root@17dns elema_web]# ls
babel.config.js  node_modules  package.json       public     src
jsconfig.json    nohup.out     package-lock.json  README.md  vue.config.js
[root@17dns elema_web]# cd src/
[root@17dns src]# cd views/
[root@17dns views]# ls
AboutView.vue  HomeView.vue

[root@17dns views]# vim HomeView.vue

8.真机访问:

  • 9
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: nginx基于域名的多虚拟主机实战配置,可以通过以下步骤来完成: 1. 首先在nginx的配置文件中添加多个server块,每个server块对应一个虚拟主机。例如: ``` server { listen 80; server_name www.example.com; root /var/www/example; index index.html; } server { listen 80; server_name www.anotherexample.com; root /var/www/anotherexample; index index.html; } ``` 2. 然后在DNS服务器中将每个域名解析到nginx服务器IP地址上。 3. 最后重新加载nginx配置文件,使其生效。 这样就可以实现基于域名的多虚拟主机配置了。当用户访问不同的域名时,nginx会根据server_name指令匹配对应的虚拟主机,并将请求转发到相应的root目录下。 ### 回答2: Nginx是一款高性能的web服务器,它的一个重要特性就是可以支持基于域名的多虚拟主机。什么是域名呢?域名就是网站的地址,例如www.baidu.com、www.sina.com.cn等等。在同一台服务器上,可以先通过域名将网站进行分类,然后再进行不同配置。Nginx的基于域名的多虚拟主机实战配置步骤如下: 1. 首先,需要安装Nginx,可以使用命令sudo apt-get install nginx进行安装; 2. 修改Nginx的配置文件,打开/etc/nginx/nginx.conf文件,找到server块,进行如下配置: server { listen 80; server_name www.example1.com; location / { root /data/www/example1; index index.html index.htm; } } server { listen 80; server_name www.example2.com; location / { root /data/www/example2; index index.html index.htm; } } 在这段配置中,Nginx为两个虚拟主机配置了不同的域名和root路径。注意,每个server块中必须有一个listen指令,用来指定虚拟主机监听的端口号。在本例中,我们使用80端口。 3. 保存配置文件并重启Nginx服务,重启命令sudo service nginx restart; 4. 在服务器上的域名服务商中添加两个域名指向服务器IP地址,例如www.example1.com指向192.168.1.1和www.example2.com指向192.168.1.1。 到此为止,我们已经配置好了基于域名的多虚拟主机。当用户在浏览器中输入www.example1.com时,Nginx会使用第一个server块中的配置作为返回结果;当用户在浏览器中输入www.example2.com时,Nginx会使用第二个server块中的配置作为返回结果。每个虚拟主机根据不同的域名,实现不同的访问路径和访问内容,提供不同的服务。这种配置方式可以提高服务器的资源利用率,降低服务器成本,更好地满足不同的业务需求。 ### 回答3: nginx是一款优秀的开源服务器软件,支持基于域名的多虚拟主机配置,实现在一台服务器上分别托管多个网站,具有高效、稳定的特点。在实际应用中,我们可以通过以下步骤来进行nginx的基于域名的多虚拟主机配置: 1. 配置nginx服务器的默认配置文件:在配置文件中,我们需要添加多个server块,每个块代表一个虚拟主机。每个块中需要设置server_name以及root指令,前者代表虚拟主机域名,后者代表虚拟主机的站点根目录。 2. 配置DNS域名解析:在DNS服务器中设置域名解析,将希望访问域名指向nginx服务器IP地址。 3. 重启nginx服务器:在配置完成后,我们需要重启nginx服务器,将新的配置生效。 配置完成后,当用户请求各自的域名时,nginx会根据请求的域名来匹配相应的虚拟主机,并将请求路由到对应的虚拟主机中。通过这种方式,我们可以在一台服务器上托管多个网站,而不必额外增加硬件花费。 在实际应用中,我们可以通过nginx的基于域名的多虚拟主机配置,来实现网站的自定义化、分流、负载均衡等需求。通过合理策划多个虚拟主机的配置,可以充分发挥服务器资源的利用率,提高网站的性能和稳定性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值