php - Nginx + Xamp + SSL 奇怪的行为

标签 php apache ssl nginx https

如果之前有人提出过这个问题,我深表歉意,但我已经尝试了所有方法,现在我被难住了。

我设置 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 下追踪到 Xampp 的那个设置,但后来迷路了。

我的全部尝试是使用 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;
			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;
        }
	
        #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;

		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 rocco.paul@gmail.com
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>                                  

所以我让 apache 监听 8080。SSL 监听 8081。我让 Nginx 监听 80,SSL 监听 443。

希望有人能指出我正确的方向。谢谢!

最佳答案

这是 Nginx 的 ssl.conf

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.key 文件都放在 /etc/nginx/ssl/

同样运行下面命令重启nginx服务

sudo /etc/init.d/nginx restart 

关于php - Nginx + Xamp + SSL 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38941565/

相关文章:

php - Laravel html_entity_decode 使用 UTF-8

php - mysql 选择最接近特定位置的纬度/经度

php - cron 作业命令中的权限被拒绝

ssl - WSO2 API Manager 私钥存储位置

php - 使用 SQL 从数据库中检索数据 - 使用 DISTINCT 时出错

php - PHP 脚本中的这条 MySQL 语句有多安全?

python - 如何在 XP 上为 python 2.6.2 配置 apache?你更喜欢什么,有框架的 python 还是没有框架的?

php - file_put_contents php 权限

ssl - 为什么 Certbot 续订时会出现 "bad handhake"错误?

ssl - 解码 ssl 数据包 wireshark