【问题标题】:Nginx + Xamp + SSL odd behaviorNginx + Xamp + SSL 奇怪的行为
【发布时间】:2016-12-20 20:39:49
【问题描述】:

如果以前有人提出过这个问题,我深表歉意,但我已经尝试了一切,现在我很难过。

我设置了 XAMPP,然后设置了 Nginx。我还将 Apache 设置为使用 SSL。我也将 Nginx 设置为使用 SSL。我试图建立一个反向代理,现在事情变得古怪了。我可以转到https://rocco.tk/dashboard/index.html,这表明 nginx 正在工作,并使用 nginx 在 443 上使用 SSL 从端口 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。

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

【问题讨论】:

    标签: php apache ssl nginx https


    【解决方案1】:

    这里是 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 
    

    【讨论】:

    • 我没有运行 php5-fpm。我在 xampp 中使用 Apache 和 php 来运行 php 脚本。
    • 那么您需要确保 ssl_certificate 和 ssl|_certificate_key url 已启用,openssl 扩展已配置且 ssl.conf 已包含在配置中。
    • 是的。我已经设置好了,它在 https 上运行良好,直到我将 Nginx 配置为侦听端口 443 和 80,然后将 Apache 配置为侦听 8080 和 8081。
    猜你喜欢
    • 1970-01-01
    • 2015-07-05
    • 2018-09-09
    • 1970-01-01
    • 2019-04-09
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多