我将webpacker添加到我的rails 5项目中,以便利用一些功能所必需的一些节点模块。我没有问题可以在本地启动和运行,但是当我部署到生产环境(使用Amazon Elastic Beanstalk)时,javascript_pack_tag指向错误的位置。例如,在此测试部署(http://production-test.us-west-2.elasticbeanstalk.com)中,标记生成的url为(http://production-test.us-west-2.elasticbeanstalk.com/packs/process_landsat-18191562216c726dbe6a.js),而其标记为(http://production-test.us-west-2.elasticbeanstalk.com/public/packs/process_landsat-18191562216c726dbe6a.js)。
我已经尝试更改webpacker.yml中的公共输出路径,但是无论我进行任何更改,它都不会在公共文件夹中显示。其余的url可以正确更新。考虑到这一点,我认为问题可能出在nginx配置上。因此,我开始对其进行修改,但仍然无法解决该问题。我敢肯定它并不太复杂,但是我似乎无法弄清楚。有人有什么想法吗?
我当前的webpacker.yml设置和nginx配置设置如下所示。
webpacker.yml
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
resolved_paths: []
cache_manifest: false
extensions:
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/
test:
<<: *default
compile: true
public_output_path: packs-test
production:
<<: *default
compile: false
public_output_path: packs
dist_dir: packs
dist_path: public/packs
cache_manifest: true
nginx_proxy.config
files:
"/etc/nginx/conf.d/websockets.conf" :
content: |
server {
location /packs/ {
root /var/app/current/public;
}
}
container_commands:
01restart_nginx:
command: "service nginx restart"
我也为nginx尝试了这种配置,但是遇到了同样的问题。
files:
"/etc/nginx/conf.d/websockets.conf" :
content: |
server {
root /var/app/current/public/;
location ^~ /packs/ {
gzip_static on;
expires max;
}
}
container_commands:
01restart_nginx:
command: "service nginx restart"