NGINX SSL无法处理子文件夹

时间:2015-04-10 12:44:33

标签: ssl nginx https

我对NGINX很新,今天我安装了ssl证书,但只处理我的索引而不是子文件夹。 例如:

www.mysite.com SSL工作正常。

www.mysite.com/forum SSL无效。

这是我在nginx中的当前配置:

default.conf
--------------------
# The default server

server {

listen     80;
listen    443 ssl;

server_name mysite.com www.mysite.com;
ssl_certificate  /etc/nginx/ssl/mysite.com/ssl-bundle.crt;
ssl_certificate_key  /etc/nginx/ssl/mysite.com/mysite.com.key;
ssl_session_timeout  5m;
ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;

location / {
 root   /usr/share/nginx/html;
#root   /usr/share/nginx/html/foro; SSL not working here :S

  index  index.html index.htm index.php;

  #limit_req   zone=flood  burst=1 nodelay;

  #charset koi8-r;

  #access_log  logs/host.access.log  main;
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d; 
}


# location ~ \.php$ {
# error_page  404              /404.php;
# root   /usr/share/nginx/html;

 #}

# redirect server error pages to the static page /50x.html
error_page   500 502 503 504  /50x.html;

rewrite ^/foro/profile/([^/]+)/?$ "/foro/index.php?pretty;action=profile;user=$1" last;
rewrite ^/foro/([-_!~*'()$a-zA-Z0-9]+)/?$ "/foro/index.php?pretty;board=$1.0" last;
rewrite ^/foro/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*)/?$ "/foro/index.php?pretty;board=$1.$2" last;
rewrite ^/foro/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/?$ "/foro/index.php?pretty;board=$1;topic=$2.0" last;
rewrite ^/foro/([-_!~*'()$a-zA-Z0-9]+)/([-_!~*'()$a-zA-Z0-9]+)/([0-9]*|msg[0-9]*|new)/?$ "/foro/index.php?pretty;board=$1;topic=$2.$3" last;


rewrite ^/foro(activate|admin|announce|ban|boardrecount|buddy|calendar|cleanperms)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(collapse|convertentities|convertutf8|coppa|deletemsg|detailedversion|display|dlattach)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(dumpdb|editpoll|editpoll2|featuresettings|featuresettings2|findmember|help|helpadmin)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(im|jsoption|jsmodify|lock|lockVoting|login|login2|logout)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(maintain|manageattachments|manageboards|managecalendar|managesearch|markasread|membergroups|mergetopics)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(mlist|modifycat|modifykarma|modlog|movetopic|movetopic2|news|notify)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(notifyboard|optimizetables|packageget|packages|permissions|pgdownload|pm|post)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(post2|postsettings|printpage|profile|profile2|quotefast|quickmod|quickmod2)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(recent|regcenter|register|register2|reminder|removetopic2|removeoldtopics2|removepoll)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(repairboards|reporttm|reports|requestmembers|search|search2|sendtopic|serversettings)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(serversettings2|smileys|smstats|spellcheck|splittopics|stats|sticky|theme)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(trackip|about:mozilla|about:unknown|unread|unreadreplies|viewErrorLog|viewmembers|viewprofile)/?$ "/index.php?pretty;action=$1" last;
rewrite ^/foro(verificationcode|vote|viewquery|who|\.xml)/?$ "/index.php?pretty;action=$1" last;



    location = /50x.html {
    root   /usr/share/nginx/html;
   }


   # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000;        
    #fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 8 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}
}

我还在测试目的中创建了一个名为ssl.conf的文件,位于nginx文件夹中:

#
# HTTPS server configuration
#
 server {

 # listen     80;
   listen    443 ssl;

    server_name mysite.com www.mysite.com;
    ssl_certificate  /etc/nginx/ssl/mysite.com/ssl-bundle.crt;
    ssl_certificate_key  /etc/nginx/ssl/mysite.com/mysite.com.key;
    ssl_session_timeout  5m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;

  location / {
  root   /usr/share/nginx/html/foro;
  index  index.html index.htm index.php;

location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
}
    }

有什么想法吗?

此致

1 个答案:

答案 0 :(得分:0)

尝试移动"位置/"在location指令之外,所以它将在server指令中。

然后将此作为您的"位置/":

location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}