2016-08-14 13 views
0

我很抱歉,如果這已被提出,但我已經嘗試了一切,現在我很難過。Nginx + Xamp + SSL的奇怪行爲

我設置了XAMPP,然後設置了Nginx。我還設置了Apache來使用SSL。我也設置了Nginx來使用SSL。我試圖建立一個反向代理,現在事情變得古怪。我可以去https://rocco.tk/dashboard/index.html,它顯示nginx正在工作,並使用SSL在443上使用nginx從端口8080在端口80上提供我的頁面。

但是,如果您點擊phpinfo,它會下載頁面。但這裏是東西....如果你去http://rocco.tk/dashboard/phpinfo.php它工作正常。如果您使用端口8080並使用僅Apache的SSL,請獲取SSL錯誤。所以我只能假設對https和php有不正確的設置。該設置我開始跟蹤到Apache下的Xamppp,但後來迷路了。

我的整個嘗試是使用nginx在apache上設置一個反向代理,這樣我就可以使用nginx作爲SSL的前端,並允許apache在該SSL上處理php。

下面是我的nginx的配置文件...

#user nobody; 
 
worker_processes 1; 
 

 
error_log logs/error.log; 
 
error_log logs/error.log notice; 
 
error_log logs/error.log info; 
 

 
pid  logs/nginx.pid; 
 

 

 
events { 
 
    worker_connections 1024; 
 
} 
 

 

 
http { 
 
    include  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 logs/access.log main; 
 

 
    sendfile  on; 
 
    #tcp_nopush  on; 
 

 
    #keepalive_timeout 0; 
 
    keepalive_timeout 65; 
 

 
    gzip off; 
 

 
server { 
 
     listen  80; 
 
     server_name rocco.tk; 
 
    
 
     location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ 
 
     { 
 
      #root html; 
 
      root C:/xampp/htdocs; 
 
\t \t \t index index.html index.htm index.php; 
 
      expires max; 
 
     } 
 
     #set default location 
 
     location/{ 
 
      proxy_pass   http://127.0.0.1:8080; 
 
     } 
 
     #Adding location for phpmyadmin 
 
     location /phpmyadmin { 
 
      proxy_pass   http://127.0.0.1:8080/phpmyadmin; 
 
      allow 127.0.0.1; 
 
      deny all; 
 
     } 
 
\t 
 
     #error_page 404    /404.html; 
 

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

 
     # proxy the PHP scripts to Apache listening on 127.0.0.1:8080 
 
     # 
 
     location ~ \.php$ { 
 

 
     proxy_set_header X-Real-IP $remote_addr; 
 
     proxy_set_header X-Forwarded-For $remote_addr; 
 
     proxy_set_header Host $host; 
 
     proxy_pass https://127.0.0.1:8081; 
 
     proxy_cache my-cache; 
 
     proxy_cache_valid 200 302 60m; 
 
     proxy_cache_valid 404  1m; 
 
     } 
 

 
     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
 
     # 
 
     #location ~ \.php$ { 
 
     # root   html; 
 
     # fastcgi_pass 127.0.0.1:9000; 
 
     # fastcgi_index index.php; 
 
     # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
 
     # include  fastcgi_params; 
 
     #} 
 

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

 

 
    # 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 ssl; 
 
     server_name rocco.tk; 
 

 
\t \t ssl on; 
 
     ssl_certificate  C:\xampp\cert.crt; 
 
     ssl_certificate_key C:\xampp\cert.key; 
 

 
     ssl_session_cache shared:SSL:1m; 
 
     ssl_session_timeout 5m; 
 
     ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; 
 
     ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+EXP; 
 
     ssl_prefer_server_ciphers on; 
 

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

 
}

這裏是我的httpd-ssl.conf中

Listen 8081 
 

 
SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4 
 
SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4 
 

 
SSLHonorCipherOrder on 
 
SSLProtocol all -SSLv3 
 
SSLProxyProtocol all -SSLv3 
 
SSLPassPhraseDialog builtin 
 
SSLSessionCache "shmcb:C:/xampp/apache/logs/ssl_scache(512000)" 
 
SSLSessionCacheTimeout 300 
 

 

 
<VirtualHost 127.0.0.1:8081> 
 

 
DocumentRoot "C:/xampp/htdocs" 
 
ServerName rocco.tk:8081 
 
ServerAdmin [email protected] 
 
ErrorLog "C:/xampp/apache/logs/error.log" 
 
TransferLog "C:/xampp/apache/logs/access.log" 
 

 
SSLEngine on 
 

 
SSLCertificateFile "conf/ssl.crt/server.crt" 
 

 
SSLCertificateKeyFile "conf/ssl.key/server.key" 
 

 
BrowserMatch "MSIE [2-5]" \ 
 
     nokeepalive ssl-unclean-shutdown \ 
 
     downgrade-1.0 force-response-1.0 
 

 

 
CustomLog "C:/xampp/apache/logs/ssl_request.log" \ 
 
      "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" 
 

 
</VirtualHost>        

所以我有阿帕奇聽8080. 8081上的SSL監聽。我有Nginx監聽80和443上的SSL監聽。

希望有人能指出我正確的方向。謝謝!

回答

0

這裏是對的ssl.conf Nginx的

HTTPS服務器

server { 
    listen  443; 
    server_name Ip_addr; 

    ssl on; 
    ssl_certificate  /etc/nginx/ssl/example.com.crt; 
    ssl_certificate_key /etc/nginx/ssl/cert-bundle.key; 

location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 

} 

確保你已經把兩個文件.CRT的/ etc/nginx的/ SSL .KEY文件/

同時運行以下命令重新啓動nginx服務

sudo /etc/init.d/nginx restart 
+0

雖然我沒有運行php5-fpm。我在xampp中使用Apache和php來運行php腳本。 –

+0

您需要確保ssl_certificate和ssl | _certificate_key url已啓用,openssl擴展已配置,並且ssl.conf已包含在配置中。 – BSB

+0

是。我已經設置好了,並且在https上工作正常,直到我配置Nginx在端口443和80上偵聽,然後配置Apache在8080和8081上偵聽。 –