nginx 配置

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
posted @   萌小心情懂  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示