File: virtual_hosts

package info (click to toggle)
nginx 1.28.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,508 kB
  • sloc: ansic: 169,561; sh: 623; perl: 439; python: 240; makefile: 130; cpp: 19
file content (155 lines) | stat: -rw-r--r-- 4,310 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
##
#  File:
#    virtual_hosts
#  Description:
#    This file is meant to deliver a basic understanding of server blocks.
##

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/Configuration
##

##
# Every "virtual host" that you serve will need to be in its own server block.
#
# server {
#	...
# }
#
# After reading this file, you should understand the structure of server blocks
# and be able to understand how to modify them to your needs.
##

server {

	# The listen directive is only needed if this server block:
	#   needs to listen for IPv6
	#   needs to listen on another port
	# If you need to listen for IPv6 then both of the following lines can
	# be included.
	# DO NOT listen for both SSL and non-SSL in the same server block.
	#listen 80; ## listen for ipv4; this line is default and implied
	#listen [::]:80 default ipv6only=on; ## listen for ipv6

	# root specifies the document root for the requests
	root /usr/share/nginx/www;

	# index specifies the list of files (in order) to be tried in the event
	# no file is requested in the URI.
	index index.html index.htm;

	# Make site accessible from http://localhost/
	server_name localhost;

	# Unless you run everything as a proxy, you will want to have a root
	# location block. This example controls how files are requested.
	location / {
		# First attempt to serve request as file, then as directory,
		# then fall back to index.html. /index.html would normally be
		# front end controller pattern for handling "clean url's" in
		# a CMS such as Drupal or Wordpress.
		try_files $uri $uri/ /index.html;
	}

	# This location block would server any requests for /doc as well
	# as anything below it.
	location /doc {
		# root changes the root directory for these requests
		root /usr/share;
		# autoindex on allows these request to display directory listings
		# if a directory was requested
		autoindex on;
		# We'll allow these requests for localhost
		allow 127.0.0.1;
		# Anyone outside is forbidden
		deny all;
	}

	# This location block would serve any requests for /images as well
	# as anything below it.
	location /images {
		# This is the same as /doc except we don't allow indexes
		root /usr/share;
		autoindex off;
		allow 127.0.0.1;
		deny all;
	}

	# This will serve the file 404.html in the event the request is not found.
	error_page 404 /404.html;

	# redirect server error pages to the static page /50x.html
	# This will hit if the server generates a 500, 502, 503, or 504 status code
	error_page 500 502 503 504 /50x.html;

	# This location block isn't actually needed because our root for the
	# server block is the same directory. However, this could be used to
	# have a central directory for all error html files.
	location = /50x.html {
		root /usr/share/nginx/www;
	}

	# proxy the PHP scripts to Apache listening on 127.0.0.1:80
	# If you're going to proxy to Apache, then just push the whole
	# request to it. You'll generally have better performance with
	# a dedicated php listener (fastcgi: php-cgi, php-fpm).
	#location ~ \.php$ {
	#	proxy_pass http://127.0.0.1;
	#}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	# This is used for passing to php-cgi and php-fpm.
	# For more information see /usr/share/doc/nginx/examples/php
	location ~ \.php$ {
		# This is where the php socket is listening.
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		include fastcgi_params;
	}

	# deny access to .htaccess, .htpasswd, and .htgroup files
	location ~ /\.ht {
		deny all;
	}
}


# another virtual host using mix of IP-, name-, and port-based configuration
server {
	listen 8000;
	listen somename:8080;
	server_name somename alias another.alias;
	root html;
	index index.html index.htm;

	location / {
		try_files $uri $uri/ /index.html;
	}
}


# HTTPS server
server {
	listen 443;
	server_name localhost;

	root html;
	index index.html index.htm;

	ssl on;
	ssl_certificate cert.pem;
	ssl_certificate_key cert.key;

	ssl_session_timeout 5m;

	ssl_protocols SSLv3 TLSv1;
	ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
	ssl_prefer_server_ciphers on;

	location / {
		try_files $uri $uri/ /index.html;
	}
}