Skip to content

Instantly share code, notes, and snippets.

@DorkNstein
Last active January 14, 2019 21:39
Show Gist options
  • Save DorkNstein/b2454dd23211ff0a367093821af3602d to your computer and use it in GitHub Desktop.
Save DorkNstein/b2454dd23211ff0a367093821af3602d to your computer and use it in GitHub Desktop.
## For Amazon linux ec2 server box
sudo yum install nginx -y
## For RHEL aws server box
## EPEL Install guide: https://support.rackspace.com/how-to/install-epel-and-additional-repositories-on-centos-and-red-hat/
sudo yum install wget -y
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -Uvh epel-release-latest-7*.rpm
## nginx install guide: https://comtechies.com/how-to-install-and-configure-nginx-on-amazon-ec2-rhel-and-ubuntu-instances.html
sudo yum repolist
sudo yum install nginx -y
sudo systemctl start nginx.service ## if systemctl doesn't work -->>> sudo service nginx start
sudo chkconfig nginx on ## if the server restarts then it automatically starts up the server
sudo vi /etc/nginx/nginx.conf ## Modify root file path
sudo systemctl restart nginx.service ## if systemctl doesn't work -->>> sudo service nginx restart
sudo systemctl status nginx.service ## if systemctl doesn't work -->>> sudo service nginx status
sudo systemctl stop nginx.service ## if systemctl doesn't work -->>> sudo service nginx stop
## if ngnix doesn't work
## Give access to desired ports in Amazon instance firewall
## change security context using following command (added that folder to selinux accesible)
sudo chcon -R -t httpd_sys_content_t <path/to/project>/dist/<folder>
### REMOVE nginx
sudo systemctl stop nginx.service
sudo chkconfig nginx off
sudo yum remove nginx -y
# 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;
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 localhost;
root /app/mendr/dist/client;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.html =404;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
# 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 /var/run/nginx.pid;
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;
index index.html index.htm;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name portal2.mendr.com;
root /app/mendr/dist/client;
if ($http_x_forwarded_proto = "http") {
rewrite ^(.*)$ https://$server_name$1 permanent;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.html =404;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
upstream apinodes {
# ip_hash;
server 127.0.0.1:3001;
}
server {
listen 80;
server_name portal2.mendr.com;
if ($http_x_forwarded_proto = "http") {
rewrite ^(.*)$ https://$server_name$1 permanent;
}
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass https://apinodes;
}
}
}
@DorkNstein
Copy link
Author

Settings for a TLS enabled server.

server {

listen 443 ssl;

listen [::]:443 ssl;

server_name localhost;

root /usr/share/nginx/html;

ssl_certificate "/etc/pki/nginx/server.crt";

ssl_certificate_key "/etc/pki/nginx/private/server.key";

# It is strongly recommended to generate unique DH parameters

# Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048

#ssl_dhparam "/etc/pki/nginx/dhparams.pem";

ssl_session_cache shared:SSL:1m;

ssl_session_timeout 10m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;

ssl_prefer_server_ciphers on;

# 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 {

}

}

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