Skip to content

Instantly share code, notes, and snippets.

@dasheck0
Last active February 7, 2021 14:13
Show Gist options
  • Save dasheck0/2ab09121eea1facb9b31140b4f918336 to your computer and use it in GitHub Desktop.
Save dasheck0/2ab09121eea1facb9b31140b4f918336 to your computer and use it in GitHub Desktop.
Default nginx.conf for VueJS apps on AWS Linux 2 instances
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
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;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /home/ec2-user/frontend/dist;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /home/ec2-user/frontend/dist;
try_files $uri /index.html;
}
location /api {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8085;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
@dasheck0
Copy link
Author

dasheck0 commented Feb 7, 2021

This is a nginx configuration you can use to setup frontend and backend on an AWS EC2 instance for the same port (which is 80). Every route prefixed with api is redirected to the backend, which runs on port 8085. This is crucial, when using a ALB to enforce HTTP/S on your instance and serve frontend and backend on the same port.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment