在Nginx

时间:2016-10-05 01:11:28

标签: php nginx url-rewriting

我试图美化我的获取变量。我的PHP代码需要两个get变量:cam和res。现在它的网站正常运作:

http://stream.foo.bar?cam=camera1&res=low

我希望能够做类似的事情:

http://stream.foo.bar/camera1/low/

我正在使用nginx,我在下面包含了我的配置以及一些日志行。任何帮助将不胜感激。

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;
    root /opt/streaming/www/;
    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;
    server_name _;
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #   # With php5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # With php5-fpm:
    #   fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
       location /stream/ {
            root /tmp/hls/;
         index stream.m3u8;
         types {
               application/vnd.apple.mpegurl m3u8;
         }
    }
    location / {
         root /opt/streaming/www/;
         try_files $uri $uri/ @pretty;
}
    location /hawk {
         rewrite ^/hawk(.*) http://stream.foo.bar/?cam=hawkcam&res=low;
         }

        location @pretty {
    rewrite ^/([^/]+)/([^/]+)/$ /index.php?cam=$1&res=$2 last;
    }
}
server {
       listen 80;
       server_name hawk.foo.bar;
       return 301 $scheme://stream.foo.bar;
       }
server {
     listen 8080;
     server_name localhost;
     location /nginx_status {
      stub_status on;
      access_log /var/log/nginx/access.log;
      allow 127.0.0.1;
      allow 192.168.41.0/24;
      deny all;
     }
}

我忘了添加nginx error.log行。当我尝试去stream.foo.bar/baycam1/high/时出现以下错误:

2016/10/04 21:12:25 [error] 10028#10028: *60 open() "/opt/streaming/www/baycam1/high/scripts/general.js" failed (2: No such file or directory), client: 192.168.68.35, server: _, request: "GET /baycam1/high/scripts/general.js HTTP/1.1", host: "stream.foo.bar", referrer: "http://stream.foo.bar/baycam1/high/"
2016/10/04 21:12:26 [error] 10028#10028: *64 open() "/opt/streaming/www/baycam1/high/scripts/custom.css" failed (2: No such file or directory), client: 192.168.68.35, server: _, request: "GET /baycam1/high/scripts/custom.css HTTP/1.1", host: "stream.foo.bar", referrer: "http://stream.foo.bar/baycam1/high/"
2016/10/04 21:12:26 [error] 10028#10028: *65 open() "/opt/streaming/www/baycam1/high/hls.js/dist/hls.js" failed (2: No such file or directory), client: 192.168.68.35, server: _, request: "GET /baycam1/high/hls.js/dist/hls.js HTTP/1.1", host: "stream.foo.bar", referrer: "http://stream.foo.bar/baycam1/high/"
2016/10/04 21:12:26 [error] 10028#10028: *60 open() "/opt/streaming/www/baycam1/high/scripts/phone.css" failed (2: No such file or directory), client: 192.168.68.35, server: _, request: "GET /baycam1/high/scripts/phone.css HTTP/1.1", host: "stream.foo.bar", referrer: "http://stream.foo.bar/baycam1/high/"
2016/10/04 21:12:26 [error] 10028#10028: *64 open() "/opt/streaming/www/baycam1/high/img/refresh.png" failed (2: No such file or directory), client: 192.168.68.35, server: _, request: "GET /baycam1/high/img/refresh.png HTTP/1.1", host: "stream.foo.bar", referrer: "http://stream.foo.bar/baycam1/high/"
2016/10/04 21:12:26 [error] 10028#10028: *65 open() "/opt/streaming/www/baycam1/high/img/share.png" failed (2: No such file or directory), client: 192.168.68.35, server: _, request: "GET /baycam1/high/img/share.png HTTP/1.1", host: "stream.foo.bar", referrer: "http://stream.foo.bar/baycam1/high/"
2016/10/04 21:12:26 [error] 10028#10028: *66 open() "/opt/streaming/www/baycam1/high/img/close.png" failed (2: No such file or directory), client: 192.168.68.35, server: _, request: "GET /baycam1/high/img/close.png HTTP/1.1", host: "stream.foo.bar", referrer: "http://stream.foo.bar/baycam1/high/"

显然,重写并不像我期望的那样正常工作。

0 个答案:

没有答案