server {
listen *:443 ssl;
server_name domain1.com;
ssl_certificate /path/to/domain1.crt;
ssl_certificate_key /path/to/domain1.key;
location / {
proxy_pass http://myapp1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
server {
listen *:443 ssl;
server_name domain2.com;
ssl_certificate /path/to/domain2.crt;
ssl_certificate_key /path/to/domain2.key;
location / {
proxy_pass http://myapp1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
http {
server {
listen 80;
client_max_body_size 4G;
server_name example.com;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://uvicorn;
}
location /static {
# path for static files
root /path/to/app/static;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream uvicorn {
server 127.0.0.1:8000;
}
}
location ~ \.(png|jpg)$ {
error_page 404 /404.png;
}
location /images/ {
try_files $uri /images/default.jpg;
}
location = /images/default.jpg {
expires 30s;
}
location /new/app/path/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:8000;
}
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
server backup2.example.com:8080 backup;
}
server {
location / {
proxy_pass http://backend;
}
}
http {
include conf/mime.types;
...
...
}
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
include conf/mime.types;
root /var/www/virtual/big.server.com/htdocs;
expires 30d;
}
pid logs/nginx_upload.pid;
events {
worker_connections 1024;
}
http {
lua_package_path '/usr/local/lib/lua/5.1/?.lua;;';
server {
listen 8001;
# download
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
# auth
auth_basic "Restricted site";
auth_basic_user_file /opt/nginx/.htpasswd;
location /download {
alias upload;
}
location ~ ^/upload_lua(/.*)?$ {
set $store_path upload$1/;
content_by_lua_file conf/lua/my_upload.lua;
}
location ~ ^/delete/(.*)$ {
set $file_path upload/$1;
content_by_lua_file conf/lua/my_delete.lua;
}
}
}
local upload = require "resty.upload"
local function my_get_file_name(header)
local file_name
for i, ele in ipairs(header) do
file_name = string.match(ele, 'filename="(.*)"')
if file_name and file_name ~= '' then
return file_name
end
end
return nil
end
local chunk_size = 4096
local form = upload:new(chunk_size)
local file
local file_path
while true do
local typ, res, err = form:read()
if not typ then
ngx.say("failed to read: ", err)
return
end
if typ == "header" then
local file_name = my_get_file_name(res)
if file_name then
file_path = ngx.var.store_path..file_name
file = io.open(file_path, "w+")
if not file then
ngx.say("failed to open file ", file_path)
return
end
end
elseif typ == "body" then
if file then
file:write(res)
end
elseif typ == "part_end" then
if file then
file:close()
file = nil
ngx.say("upload to "..file_path.." successfully!")
end
elseif typ == "eof" then
break
else
-- do nothing
end
end
<!DOCTYPE html>
<html>
<head>
<title>Upload your files</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>Upload your file</p>
<input type="file" name="uploaded_file"></input><br />
<input type="submit" value="Upload"></input>
</form>
</body>
</html>
<?PHP
if(!empty($_FILES['uploaded_file']))
{
$path = "uploads/";
$path = $path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['uploaded_file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
Error response from daemonЧто-то пошло не так.
docker run hello-world
запускается?docker run -d -p 80:80 webserver-image:v1
тут 80 портcurl localhost:8000
тут 8000 портserver grand-study.com;
nginx resolves hosts at configuration phase, because for a long time
nginx has no non-blocikng resolver. Currently it has, but resolves
hosts at run-time only if proxy_pass contains variables in any place,
not necessarily in the host part.
--
Igor Sysoev
sysoev.ru/en
location /yabloki/ {
rewrite ^/yabloki/(.*) http://yabloki.mysite.com/$1 permanent;
return 403;
}
server {
listen 80;
server_name example.com;
location ~ ^/products/(.*)$ {
proxy_pass http://catalog.example.com/$1;
}
}
server {
# ...
server_name domain.tld www.domain.tld;
return 301 $scheme://subdomain.domain.tld$request_uri;
}
server {
server_name subdomain.domain.tld;
# ...
}
server {
listen 443 ssl;
listen [::]:443 ssl;
access_log /var/log/nginx/api.site.ru_access.log;
ssl_certificate /etc/ssl/api.site.ru.crt;
ssl_certificate_key /etc/ssl/api.site.ru.key;
server_name api.site.ru;
root /root/api.site.ru;
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
location / {
# тут заголовки и др.
proxy_pass http://127.0.0.1:3000; # Тут адрес ноды которая отдает API (уже запущенная)
}
}
nginx -t
(не забываем про сертификаты)location /site1 {
alias /var/www/site1;
}
location /site2 {
alias /var/www/site2;
}
location /site3 {
alias /var/www/site3;
}
server {
root /var/www/html;
index index.html index.html;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /site1 { alias /var/www/site1; }
location /site2 { alias /var/www/site2; }
location /site3 { alias /var/www/site3; }
location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
access_log off;
expires max;
log_not_found off;
}
location ~* \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
The "set" directive isn't something essential, and actually it is just a
directive from the rewrite module.
See here how it works:
nginx.org/en/docs/http/ngx_http_rewrite_module.html
It is evaluated on the rewrite phase of request processing. Thus, if
the request is finalized before this phase, then your variable is left
uninitialized.
To debug your locations and for better understanding what is going on,
you can use nginx debug log: nginx.org/en/docs/debugging_log.html
uninitialized_variable_warn off;
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name 111.111.111.11;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ^~ /admin/ {
auth_basic "Admin Login";
auth_basic_user_file /etc/apache2/.htpasswd;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
}
location ~ /\.ht {
deny all;
}
}