B
B
bigdogsru2011-06-01 11:37:22
Nginx
bigdogsru, 2011-06-01 11:37:22

Nginx 1.0.3 - how to configure ONLY to serve static?

I can’t configure Nginx 1.0.3 - once you connect it, .htaccess files are immediately ignored, and by other signs it looks like it processes php files itself, without giving them to Apache.

I took the config from a working 0.8 from another VPS, everything works as it should. The config was created automatically by the ISPManager panel - I just threw out extra hosts from it, changed the path to the log and changed the IP.

CentOS 5.4, Nginx installed from CentALT.

Here is the config:

user  nginx;
worker_processes  2;
worker_rlimit_nofile 100000;

error_log   /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
    use epoll;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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;
    server_tokens   off;
    gzip            on;
    gzip_static     on;
    gzip_comp_level 5;
    gzip_min_length 1024;
    keepalive_timeout  65;
    limit_zone   myzone  $binary_remote_addr  10m;

    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;



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

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

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

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

  client_max_body_size 16m;
  log_format  isp '$bytes_sent $request_length';
  
  server {
    listen 50.57.78.248:80;
    server_name dogstudio.su dog-studio.org *.dog-studio.org *.dogstudio.su www.dog-studio.org www.dogstudio.su;
    rewrite	^(/manager/.*)$	https://$host$1	permanent;
    rewrite ^(/manager/.*)$	https://$host$1	permanent;
    error_page 404 = @fallback;
    location ~* ^/(webstat/|awstats|webmail/|myadmin/|manimg/) {
      proxy_pass http://50.57.78.248:8080;
      proxy_redirect http://dogstudio.su:8080/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location / {
      proxy_pass http://50.57.78.248:8080;
      proxy_redirect http://dogstudio.su:8080/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar)$ {
      set $proot "/home/dogstudio/public_html/dogstudio.su/public";
      if ( $host = "dog-studio.org" ) {
        break;
      }
      if ( $host = "dogstudio.su" ) {
        break;
      }
      if ( $host = "www.dog-studio.org" ) {
        break;
      }
      if ( $host = "www.dogstudio.su" ) {
        break;
      }
      if ( $host ~* ^((.*).dog-studio.org)$ ) {
        set $proot /home/dogstudio/public_html/$1/public;
        break;
      }
      if ( $host ~* ^((.*).dogstudio.su)$ ) {
        set $proot /home/dogstudio/public_html/$1/public;
        break;
      }
      access_log /home/dogstudio/public_html/dogstudio.su/log/access.nginx.log;
      root $proot;
    }
    location @fallback {
      proxy_pass http://50.57.78.248:8080;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
    }
  }
}


What is wrong?

There is a site on HostCMS (dogstudio.su), if I prescribe port 80 to Apache and disable nginx, it displays normally; if I prescribe Apache 8080 and run nginx, it gives a CMS error "License key not found". The same site with the same config on another VPS (dog-studio.org) works as it should with nginx enabled.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
whiteglasses, 2011-06-01
@whiteglasses

nginx does not use .htaccess files. Only your configs.
It is possible in more detail about "and by other signs it seems that he himself processes php-files without giving them to Apache"

C
crea7or, 2011-06-01
@crea7or

The error seems to be in cms because nginx itself is not able to process php. My nginx is configured exactly like this, it gives only statics, and php chews Apache.
In general, I suggest running Apache on localhost and changing:

location / {
      proxy_pass http://50.57.78.248:8080;
      proxy_redirect http://dogstudio.su:8080/ /;

on the
location / {
      proxy_pass         http://127.0.0.1/;
      proxy_redirect     off;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question