Nginx
vue项目配置好后,刷新页面会出现404?
方案:增加重定向 try_files $uri $uri/ /index.html;
mac配置Nginx
1、brew install nginx
安装nginx
2、brew info nginx
查询nginx信息
3、查看/修改nginx的配置文件:打开文件 /opt/homebrew/etc/nginx/
,可以看到有nginx.conf 文件,在该文件同级目录下新建vhosts文件,且在nginx.conf文件中增加include vhosts/*.conf;
,引入vhosts下所有的配置文件 单个配置文件的代码如下:
server {
listen 9001;
server_name localhost;
location / {
root html/www/web;
try_files $uri $uri/ /index.html;
index index.html;
}
location /h5 {
alias html/www/h5;
try_files $uri $uri/ /h5/index.html;
}
}
以下为linux配置参考:
server {
listen 443;
server_name test.***.com;
ssl_certificate cert/***.crt;
ssl_certificate_key cert/***.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /data/www/web;
try_files $uri $uri/ /index.html;
index index.html;
}
location /h5 {
alias /data/www/h5;
try_files $uri $uri/ /h5/index.html;
}
location /api {
proxy_pass http://127.0.0.1:30003;
proxy_redirect off;
proxy_set_header Host ***.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_read_timeout 90;
client_max_body_size 500m;
}
}
4、启动nginx
sudo nginx
5、重启nginx
sudo nginx -s reload
标签:index,配置,uri,h5,nginx,html,proxy
From: https://www.cnblogs.com/gao-xiaomeng/p/18358402