Giter Club home page Giter Club logo

nginx-basic's Introduction

NGINX is open-source web server software used for reverse proxy, load balancing, and caching. It's important to understand, especially for backend developer.

server: nginx, serve web content to browser (web server)

client - network - nginx - server

can be incraise server, and serve to network as one server? (nginx)

reverse proxy, load balancer, encryption, scalability

Reload nginx nginx -s reload

Serve Static Conten

http {
	server {
		listen 8080;
		root /var/www/nginx-basic;
		index index.html;
	}
}
events {

}
  • Make sure to give proper access to the file

Mime Types

http {

	include mime.types;

	server {
		listen 8080;
		root /var/www/nginx-basic/;
		index index.html;

		location / {
			try_files $uri $uri/ =404;
		}

		location /css/ {
			try_files $uri $uri/ =404;
		}
	}
}

events {

}

Proxy Pass

http {
		server {
		listen 80; # Assuming you want to serve on the default HTTP port

		server_name _;

		location / {
			proxy_pass http://localhost:3000; # Pass requests to your Rails app running on localhost
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto $scheme;
		}
	}

}

events {

}

Location context

http {

	include mime.types;

	server {
		listen 8080;
		root /var/www/nginx-basic/;
		index index.html;

		location /fruits {
			root /var/www/nginx-basic/;
			index index.html;
		}

		location /carbs {
			alias /var/www/nginx-basic/fruits;
			index index.html;
		}

		# try search
		location /vegetables {
			alias /var/www/nginx-basic/;
			try_files /vegetables/veggies.html /index.html =404;
		}

		# regex
		location ~* /count/[0-9] {
			alias /var/www/nginx-basic/;
			try_files /index.html =404;
		}

		location / {
			try_files $uri $uri/ =404;
		}

		location /css/ {
			try_files $uri $uri/ =404;
		}
	}
}

events {

}

Redirect & rewrite

http {

	include mime.types;

	server {
		listen 8080;
		root /var/www/nginx-basic/;
		index index.html;

		location /fruits {
			root /var/www/nginx-basic/;
			index index.html;
		}

		location /carbs {
			alias /var/www/nginx-basic/fruits;
			index index.html;
		}

		# try search
		location /vegetables {
			alias /var/www/nginx-basic/;
			try_files /vegetables/veggies.html /index.html =404;
		}

		# regex
		location ~* /count/[0-9] {
			alias /var/www/nginx-basic/;
			try_files /index.html =404;
		}

		# Redirect
		location /crops {
			return 307 /fruits;
		}

		# Rewrite
		rewrite ^/number/(\w+) /count/$1;

		location / {
			try_files $uri $uri/ =404;
		}

		location /css/ {
			try_files $uri $uri/ =404;
		}
	}
}

events {

}

nginx-basic's People

Contributors

anjasfedo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.