国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

nginx配置多個前端項目實現(xiàn)步驟

瀏覽:16日期:2023-06-15 15:23:36

最近一臺服務(wù)器要配置多個前端項目,當(dāng)然前后端分離就需要nginx來配置了。

單個項目還好說,如下
修改nginx的nginx.conf配置文件

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;pid /usr/local/nginx/logs/nginx.pid;events {    worker_connections  1024;}http {     server {listen       8000;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {    root   /var/www/;    #index  index.html index.htm;}location ~ /static/.*\.(gif|jpg|jpeg|png|bmp|swf)$ {    root /var/www/project;}location ~ /static/.*\.(js|css)$ {    root /var/www/project;}location = /project {    root   /var/www/project;    index  index.html index.htm;}       }}

但是出現(xiàn)了多個項目也需要在nginx.conf配置

項目基于vue cli 開發(fā)的,打包時需要配置一下js,css 等靜態(tài)文件的連接地址
修改如下配置文件

根據(jù)項目名字或者路徑名 修改 在對應(yīng)的項目里

assetsPublicPath: "/project/"-----------------------assetsPublicPath: "/project1/"

然后再來配置nginx.conf

user root;worker_processes  1;pid /usr/local/nginx/logs/nginx.pid;events {    worker_connections  1024;}http {    include       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  logs/access.log  main;    sendfileon;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {listen       8000;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {    root   /var/www;    #index  index.html index.htm;}location = /project1 {    root   /var/www/project1;    try_files $uri $uri/ /project1/index.html;    index  index.html index.htm;}location = /project2{    root /var/www/project2;    try_files $uri $uri/ /project2/index.html;    index  index.html index.htm;}    }}

此處注意呢 user root; 需要加上, 不然范圍報 500,
然后重啟一下nginx

 先停止  ./nginx -s quit 再重啟 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

當(dāng)然nginx -s reload 可以 ,但是可能報錯, 解決就用上面辦法

成功訪問
192.168..:8000/project/index.html
192.168..:8000/project1/index.html

到此這篇關(guān)于nginx配置多個前端項目實現(xiàn)步驟的文章就介紹到這了,更多相關(guān)nginx配置多前端項目內(nèi)容請搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!

標(biāo)簽: Nginx
主站蜘蛛池模板: 长治县| 常熟市| 博野县| 镇原县| 泰来县| 呼玛县| 海口市| 义马市| 浦江县| 石楼县| 三都| 谷城县| 教育| 泗阳县| 泾源县| 新余市| 中江县| 宁波市| 正定县| 屯昌县| 武冈市| 茂名市| 陆良县| 澄江县| 凤庆县| 渭源县| 陵水| 收藏| 娄底市| 苍南县| 怀柔区| 朝阳区| 册亨县| 肇州县| 榆社县| 象州县| 高淳县| 芜湖市| 晴隆县| 合作市| 文安县|