Docker内Nginx容器部署前端项目
1.打包前端页面
vue的前端页面则通过build方法打包出dist文件夹
2.创建用与nginx文件映射的文件夹
创建一个nginx文件夹,内存放:
www文件夹,用于存放html文件
cart文件夹,用于存放证书
conf文件夹,用于存放扩展配置文件
log文件夹,用于存放运行日志
以及一个nginx.conf文件,此文件是nginx的配置文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
nginx.conf文件内的默认代码:
进入conf文件夹,这里面存放一个扩展的.conf配置文件,此文件的名称随意
内容:
server {
listen 80;
listen [::]:80;
#localhost处用于填写域名,如填写www.xxx.com,localhost代表本机
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
#进入www文件夹,打开inde.html或者index.htm
root /www;
index index.html index.htm;
}
#如果发生错误,会自动跳出404.html进行提示
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
3.用docker创建nginx容器,并且配置端口与文件的映射关系
docker配置:
docker run --name nginx -d --restart=always -p 80:80 -v
/Users/renzilong/Documents/docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v /Users/renzilong/Documents/docker/nginx/cart:/etc/nginx/cart -v /Users/renzilong/Documents/docker/nginx/conf:/etc/nginx/conf.d -v /Users/renzilong/Documents/d
–name 后填写的字符是创建出的容器名称
–restart=always 代表开机自动启动
-p代表端口映射,80:80 冒号前的80代表本机的端口,冒号后的代表要映射的容器内部的端口
-v与-p同理,是用本机里的文件映射docker容器里的文件
4.用网页打开
Warning: Undefined variable $aria_req in /www/wwwroot/l.lvovl.cn/wp-content/themes/JieStyle-Two-master/comments.php on line 26
Warning: Undefined variable $aria_req in /www/wwwroot/l.lvovl.cn/wp-content/themes/JieStyle-Two-master/comments.php on line 27
Warning: Undefined variable $aria_req in /www/wwwroot/l.lvovl.cn/wp-content/themes/JieStyle-Two-master/comments.php on line 28