【发布时间】:2019-10-13 13:00:46
【问题描述】:
基本上,我使用 gatsby build 命令构建了我的 gatsby 站点,我想使用 Nginx 为 public 目录提供所有静态文件。
我的网站位于/var/www/mywebsite,还有一些测试html 基本页面位于/var/www/test。
我可以提供该测试页面并且它工作正常,但是当我将目录更改为该 gatsby 站点时它不起作用并且我得到Forbiden 403 error。
我认为这可能是我的配置,但我是否必须对 gatsby 做一些特别的事情才能正确地提供所有这些静态文件?
nginx.conf
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
index index.html index.htm;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
server_name mywebsite.com www.mywebsite.com; # managed by Certbot
# root /var/www/test; # <-- This gets served
root /var/www/mywebsite/public; # <-- This doesn't
index index.html index.html;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# some ssl certificates...
}
server {
if ($host = www.mywebsite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mywebsite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name mywebsite.com www.mywebsite.com;
return 404; # managed by Certbot
}
}
我读到我不需要 sites-available 和 sites-enabled 目录,它可以在主 nginx.conf 文件中配置,也可以从 nginx.conf 本身的 conf.d 目录中包含。
【问题讨论】:
标签: reactjs nginx digital-ocean gatsby static-site