zoukankan      html  css  js  c++  java
  • Nginx相关问题

    前端页面刷新404

      vue单页因微信分享和自动登录需要,对于URL中存在’#’的地址,处理起来比较坑。用history模式就不会存在这样的问题。但是换成history模式,就会有个新的问题,就是页面刷新后,页面就无法显示了(404)。对于这个问题,我们只需要在服务器配置如果URL匹配不到任何静态资源,就跳转到默认的index.html。
    server {
            listen       8888;
            server_name  localhost;
            root        E:/vue/my_project/dist;
            location / {
                try_files $uri $uri/ @router;
                index  index.html index.htm;
            }
     
            location @router {
                rewrite ^.*$ /index.html last;
            }
          
      }

    解析远程真实IP

    server {
            listen       8888;
            server_name  localhost;
            root        E:/vue/my_project/dist;
            location / {
                index  index.html index.htm;
                proxy_set_header X-Real-IP $remote_addr;
            }
          
      }

    Windows下nginx

    #启动
    start nginx
     
    #停止
    nginx -s stop
     
    #重启
    nginx -s reload

    Linux下ningx

    #首先利用配置文件启动Nginx:
    nginx -c /usr/local/nginx/conf/nginx.conf
     
    重启服务: 
    service nginx restart
     
    #快速停止或关闭Nginx:
    nginx -s stop
     
    #正常停止或关闭Nginx:
    nginx -s quit
     
    # 配置文件修改重装载命令:
    nginx -s reload

    完整配置案例

    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;
    
        upstream fabric {
            server 192.168.1.118:8085;
        }
    
        server {
            listen       9527;
            server_name  192.168.1.118;
            client_max_body_size    1000M;
            root   D:/software/nginx-1.14.0/dist;
    
            location / {
                try_files $uri $uri/ @router;
                index  index.html index.htm;
                proxy_set_header X-Real-IP $remote_addr;
            }
            
            location @router {
                rewrite ^.*$ /index.html last;
            }
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
  • 相关阅读:
    从 洛伦兹变换 的 讨论 想到
    量子力学 的 新架构
    python中requirements.txt文件的读写
    关于pip安装依赖包时发生的编码格式错误
    odoo 连接其他服务器上的PostgreSQL数据库
    odoo from视图操作记录
    Postgresql sq distinct() 函数的用法
    Postgresql sql查询结果添加序号列
    odoo pivot透视图 常用属性
    Postgresql 获取当前时间
  • 原文地址:https://www.cnblogs.com/jockming/p/12170571.html
Copyright © 2011-2022 走看看