?背景:
若依移動端的項目:整合了uview開源ui框架
部署流程
1. 配置后端請求接口基本路徑地址:
2. 打包復制到nginx下:nginx/htm/newxss, (newxss目錄手動創(chuàng)建)
3.在nginx上配置了站點與api代理?
Nginx配置
安裝個穩(wěn)定版本的:nginx-1.24.0
部署配置:
1.增加了網(wǎng)站:8083端口的,?網(wǎng)站目錄在nginx/html下的子目錄:newxss
之后就可以愉快的使用這個端口了。如下,使用他來指向一個新網(wǎng)站項目。
2. 配置跨域轉(zhuǎn)發(fā)? ?/apixss,
3.多個后臺服務器的話,增加跨域配置如?/secondapi,?把它們寫在8083端口的server{}對象里。
?location /secondapi {
? ? ? ? ? ? ? ? ? # 后端的真實接口 http://10087whhkj.com/webapi
? ? ? ? ? ? ? ? ? proxy_pass http://10087.whhkj.com/webapi;? ? ? ? ? ? }
4. 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 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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#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 html;
}
}
server {
# 監(jiān)聽的端口號
listen 8083;
server_name 192.168.10.101;
# 配置根目錄的地址是以 nginx 下的 html 文件夾為根目錄來查找的
root html;
location / {
root html/newxss;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# 關鍵步驟 http://192.168.10.101/apixss/ 開頭的請求都會轉(zhuǎn)發(fā)到下面proxy_pass
location /apixss {
# 后端的真實接口 http://10086.whhkj.com/webapi
proxy_pass http://10086.whhkj.com/webapi;
}
}
}
5. 重啟nginx:? ?nginx -s reload,就可以正常訪問了。
網(wǎng)域運行:?
遇到404,是跨域路徑?jīng)]匹配到,405是匹配到路徑,但是路徑錯。
部署到阿里云nginx
阿里云 linux 的nginx 配置uni-app的前端項目vue_Lan.W的博客-CSDN博客
一直404,405 排除:
1. 服務器中,有兩個nginx,有可能造成跨域失效。文章來源:http://www.zghlxwxcb.cn/news/detail-849105.html
2.?多次改配置,從網(wǎng)上拷貝一些不適合的配置導致,接口,路徑什么都對上就是404,405,那么,把整個nginx.conf刪除,重新拷貝一個干凈的過來,再做配置。文章來源地址http://www.zghlxwxcb.cn/news/detail-849105.html
到了這里,關于uni-app 前端項目(vue)部署到本地win系統(tǒng)Nginx上 http的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!