2017-02-02 64 views
0

,所以我有遊民端口轉發nginx的對流浪漢不斷下探端口

這裏是vagrantfile

Vagrant.configure("2") do |config| 

    config.vm.provider "virtualbox" do |v| 
     v.memory = 2048 
     v.cpus = 4 
    end 

    config.berkshelf.enabled = true 
    config.berkshelf.berksfile_path = "./Berksfile" 
    config.omnibus.chef_version = :latest 

    config.vm.network :forwarded_port, guest: 80, host: 8080 
    config.vm.network :forwarded_port, guest: 22, host: 2020 

end 

下面是nginx.conf

user www-data; 
worker_processes 4; 

error_log /var/log/nginx/error.log; 
pid  /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
} 

http { 

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


    access_log /var/log/nginx/access.log; 

    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 

    keepalive_requests 100; 
    keepalive_timeout 65; 


    gzip on; 
    gzip_http_version 1.0; 
    gzip_comp_level 2; 
    gzip_proxied any; 
    gzip_vary off; 
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml text/javascript application/javascript application/json text/mathml; 
    gzip_min_length 1000; 
    gzip_disable  "MSIE [1-6]\."; 


    variables_hash_max_size 1024; 
    variables_hash_bucket_size 64; 
    server_names_hash_bucket_size 64; 
    types_hash_max_size 2048; 
    types_hash_bucket_size 64; 



    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

這裏sites_enabled /默認

server { 
    listen 80; 
    server_name precise64; 

    access_log /var/log/nginx/localhost.access.log; 

    root /vagrant/site/www/public; 
    index index.php index.html index.htm; 

    location/{ 
    try_files $uri $uri/ /index.php?$query_string; 
    } 

    location ~ \.php$ { 
    try_files $uri /index.php =404; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_pass unix:/run/php/php7.1-fpm.sock; 
    fastcgi_index index.php; 
    } 
} 

這是蘇是,每次我去http://localhost:8080/somedirectory在我的瀏覽器,nginx的結束了重定向(301)http://localhost/somedirectory

如果我訪問某個特定的文件,它不會做重定向預期

這是爲什麼發生,我怎樣才能防止nginx丟棄端口?

回答

0

我沒有在您的NGINX配置中看到重定向,所以我的猜測是它來自您的PHP應用程序。

+0

它恰好適用於任何目錄,即使它沒有php腳本 – m4jesticsun

+0

您的try_files語句中的默認值是運行php腳本。 NGINX可能無法找到目錄或有權限,並且默認爲php腳本。沒有看到您的訪問日誌,很難說更多。 –