为了我自己的目的配置 nginx

为了我自己的目的配置 nginx

任何人都可以帮我nginx.conf根据以下任务进行编辑吗?我已经完成了基本配置。这里是还必须设置的选项列表(我还没有这样做):

1.Image files should be served by nginx with "Expires: 21 days" header added 
2.Logging of requests to "/somelogo.ico" should be disabled. All other requests should be proxied to another web server running on
local IP address on port 8080
3.Virtual host should accept requests to all "test.org" subdomains;

在这里我的nginx.conf

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/test.org/access.log  main;


   server {
      location / {
                    root     /var/www/test.org/html;
             }
       location /images/ {
                root  /var/www/test.org/images;
             }
          }
       }

答案1

尝试这个:

如果使用 URI 指定 proxy_pass 指令:

location / {
    proxy_pass      http://127.0.0.1:8080/mapped_dir/;
    proxy_set_header    Host            $host;
}

然后

test.org/xxxxx will proxy to  http://127.0.0.1:8080/mapped_dir/xxxxx

会议

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/test.org/access.log  main;


   server {
      listen 80;
      # handle requests containing anything.test.org in the HTTP header hosts field
      server_name *.test.org;

    location / {
        proxy_pass      http://127.0.0.1:8080/mapped_dir/;
        proxy_set_header    Host            $host;
    }
       location /images/ {
                root  /var/www/test.org/images;
                add_header "Expires:" "21 days" always;
             }
       # turn off logging for requests to /somelogo.ico
       location /somelogo.ico {
             access_log off;
          }
       }

相关指令的信息

相关内容