Linux/Apache/Nignx

关于react-router-dom的部署Apache&ngin

2019-06-30  本文已影响0人  吴佳浩

今天主要是整理BrowserRouter 去掉#之后 服务器的具体配置,主要讲述以下两种 Apache&nginx

<VirtualHost *:8080>
  ServerName example.com
  DocumentRoot /var/www/httpd/example.com
  <Directory "/var/www/httpd/example.com">
    RewriteEngine on
    #Do not rewrite files or directories
    #不要重写文件或目录
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    # Rewrite everything else to index.html to allow html5 state links
    #将其他所有内容重写为index.html以允许html5状态链接
    RewriteRule ^ index.html [L]
  </Directory>
</VirtualHost>

#出处吴佳浩[https://www.jianshu.com/u/c817dc83befd](https://www.jianshu.com/u/c817dc83befd)

这告诉Apache提供任何存在的文件,但如果它们不存在,只需提供/ index.html而不是'404:not found`。

通过提供以下位置来更改虚拟主机配置(通常位于/etc/nginx/conf.d/vhosts.conf中):

server {
    listen 80 default_server;
    server_name /var/www/example.com;

    root /var/www/example.com;
    index index.html index.htm;      

    location ~* \.(?:manifest|appcache|html?|xml|json)$ {
      expires -1;
      # access_log logs / static.log; #我通常不包含静态日志
      # access_log logs/static.log; # I don't usually include a static log
    }

    location ~* \.(?:css|js)$ {
      try_files $uri =404;
      expires 1y;
      access_log off;
      add_header Cache-Control "public";
    }
    #包含文件扩展名的任何路由(例如/devicesfile.js)
    # Any route containing a file extension (e.g. /devicesfile.js)
    location ~ ^.+\..+$ {
      try_files $uri =404;
    }

    # Any route that doesn't have a file extension (e.g. /devices)
    location / {
        try_files $uri $uri/ /index.html;
    }
}

转载请留言并著名出处,虽然我不知道为什么最近简shu总是莫名奇妙的封文章,但是能给大家提供一些帮助我很开心,也希望更多的前端小伙伴能够成长的更全面。
------------------------------------------------------------------------------------------------------------------吴佳浩201801

上一篇下一篇

猜你喜欢

热点阅读