方案是我已经在aws上创建了一个实例,并且在我的rails上创建了一个实例,并在localhost:3000上使用rails s命令运行。并且服务器正在使用PUMA运行。
现在我想看到我的应用在公共DNS上运行http://ec2-13-56-156-255.us-west-1.compute.amazonaws.com/
为此我已经安装了nginx web服务器,我能够看到nginx的默认索引页面,但是当我在nginx.conf文件中进行更改以查看我的应用程序时,它给出了403错误。变化如下。
文件路径:/etc/nginx/nginx.conf
user ec2-user;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
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;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
upstream app {
server 127.0.0.1:3000;
#server unix:///path_to_my_app/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 13.56.156.255;
root /home/ec2-user/Projects/aqua_web_v1.0;
#root /usr/share/nginx/html;
#location / {
#}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
答案 0 :(得分:0)
您需要通过复制默认文件来创建服务器块配置文件:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
现在用sudo
previlege
sudo nano /etc/nginx/sites-available/example.com
然后将您的主机名添加到:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/example.com;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
了解更多详细信息,请查看此digitalocean指南: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04